I am trying to render a .png image to the screen using C++, SDL and glut.
This the texture I made using paint
This is what I get on the screen:
Does anyone have an idea what could cause this?
How I loaded the image:
void Main::loadStuff() {
SDL_Surface* surface = IMG_Load("C:\\Users\\VliegendeGeit\\Desktop\\Programming\\C++ Projects\\OpenGL\\texture.png");
if (!surface) {
std::cout << "errror";
return;
}
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
int Mode = GL_RGB;
if(surface->format->BytesPerPixel == 4){
std::cout << "errror2";
Mode = GL_RGBA;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surface->w,surface->h, 0, GL_RGB,GL_UNSIGNED_BYTE,surface->pixels);
SDL_FreeSurface(surface);
}
How I rendered the image:
///TEXTURE
glBindTexture(GL_TEXTURE_2D,texture);
glEnable(GL_TEXTURE_2D);
int X = 0;
int Y = 0;
int Width = 1;
int Height = 1;
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex3f(X, Y, 0);
glTexCoord2f(0, 1); glVertex3f(X + Width, Y, 0);
glTexCoord2f(1, 1); glVertex3f(X + Width, Y + Height, 0);
glTexCoord2f(1, 0); glVertex3f(X, Y + Height, 0);
glEnd();
glDisable(GL_TEXTURE_2D);
Ps.
Yes I made the GLuint texture
variable, it is static defined in the header file, oh and there are no errors it could not load or something.