Basic texture render

Started by
3 comments, last by Shawn619 10 years, 11 months ago

I want a texture across my entire window, but i'm getting some funky results.

Also, I'm using http://www.videotutorialsrock.com/opengl_tutorial/textures/text.php .bmp loader

This is my display callback function:


void drawOrtho2Scene() {
 
glClear(GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, windowWidth, windowHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glOrtho(0.0f, windowWidth, 0.0f, windowHeight, 0.0f, 1.0f);
 
 
//enables/disables
glDisable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
 
 
//bind texture
glBindTexture(GL_TEXTURE_2D, aboutTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 
glColor3f(1.0f, 1.0f, 1.0f);
 
 
//draw about screen
glBegin(GL_QUADS); 
glTexCoord2f( 0.0f, 0.0f );glVertex2f(0, 0); 
 
//top-left
glTexCoord2f( 1.0f, 0.0f );glVertex2f(windowWidth, 0); 
 
//top-right
glTexCoord2f( 1.0f, 1.0f );glVertex2f(windowWidth, windowHeight); 
 
//bottom-right
glTexCoord2f( 0.0f, 1.0f );glVertex2f(0, windowHeight); 
 
//bottom-left
glEnd();
 
 
//enables/disables
glDisable(GL_TEXTURE_2D);
 
glutSwapBuffers();
}

This is the original image:

20iz5hf.jpg

This is how it displays it:

xppxkg.jpg

Advertisement

The first thing that jumps out to me is that OpenGL screen coords are -1.0 to 1.0, not 0.0 to 1.0. glOrtho should be taking -windowWidth etc. as arguments, and also change your vertex positions to be -1.0 to 1.0 (Not the texture coords though).

The coords are just fine. I think your problem is with how you create the texture. BMP format doesn't have alpha and you're probably using it as RGBA or something? Check the glTexImage2D function call. I would also recommend to use gDebugger to see what the texture actually looks like.

Derp

The first thing that jumps out to me is that OpenGL screen coords are -1.0 to 1.0, not 0.0 to 1.0. glOrtho should be taking -windowWidth etc. as arguments, and also change your vertex positions to be -1.0 to 1.0 (Not the texture coords though).

I get the same result, unfortunately.

The coords are just fine. I think your problem is with how you create the texture. BMP format doesn't have alpha and you're probably using it as RGBA or something? Check the glTexImage2D function call. I would also recommend to use gDebugger to see what the texture actually looks like.

Yes, I think the problem is with loading the .bmp texture.

I actually loaded the .bmp file from video tutorials rock, and it worked perfectly.

30swtia.jpg

So, what is wrong with my .bmp? Is there a specific way I should export my .bmp?

Solved! My .bmp resolution had to be of a power of 2.


Thanks everyone

This topic is closed to new replies.

Advertisement