Jump to content

  • Log In with Google      Sign In   
  • Create Account


Basic texture render


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Shawn619   Members   -  Reputation: 342

Like
0Likes
Like

Posted 04 May 2013 - 09:52 AM

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



Sponsor:

#2 OandO   Members   -  Reputation: 683

Like
0Likes
Like

Posted 04 May 2013 - 11:20 AM

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).



#3 Sponji   Members   -  Reputation: 1142

Like
0Likes
Like

Posted 04 May 2013 - 12:07 PM

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

#4 Shawn619   Members   -  Reputation: 342

Like
0Likes
Like

Posted 04 May 2013 - 12:26 PM

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?



#5 Shawn619   Members   -  Reputation: 342

Like
0Likes
Like

Posted 04 May 2013 - 01:50 PM

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


Thanks everyone






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS