Jump to content
  • Advertisement
Sign in to follow this  
Shawn619

OpenGL Basic texture render

This topic is 1878 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!