Skip to main content
gamedev.net
🔒 Locked

Problem drawing Image

Started by Stormtrooper 2 replies 700+ views
Original Post
Stormtrooper
Stormtrooper
As you can see from this image that I am having a problem drawing a 2d image. This is the same GL_QUADS code I use to draw a colored rectangle and that works fine. EDIT: I fixed the shape...now I just need to fix the texture being stretched. Here is my drawing code:

	if(image == NULL)
		return;

	float texX1	= src.x / (float)image->getWidth();
	float texY1 = src.y / (float)image->getHeight();
	float texX2 = (src.x + src.width) / (float)image->getWidth();
	float texY2 = (src.y + src.height) / (float)image->getHeight();

	glBindTexture( GL_TEXTURE_2D, image->getTexture() );
	
	glEnable( GL_TEXTURE_2D );

	glBegin( GL_QUADS );
		glTexCoord2f( texX1, texY1 );
        glVertex3f( dest.x , dest.y, 0 );

		glTexCoord2f( texX1, texY2 );
        glVertex3f( dest.x + src.width, dest.y, 0 );

		glTexCoord2f( texX2, texY2 );
        glVertex3f( dest.x + src.width, dest.y + src.height, 0 );

		glTexCoord2f( texX2, texY1 );
        glVertex3f( dest.x, dest.y + src.height, 0 );
    glEnd();

	glDisable( GL_TEXTURE_2D );


Fahrenheit451
Fahrenheit451
Have you tried using fixed texture coordinates to verify that works?

Assuming counter-clockwise, that would be:

glTexCoord2f(0.0f,1.0f);
glTexCoord2f(1.0f,1.0f);
glTexCoord2f(1.0f,0.0f);
glTexCoord2f(0.0f,0.0f);
Fahrenheit451
Fahrenheit451
If you get the image texture coordinates working with fixed coordinates, albeit upside down, then the problem must be in your texture coordinate calculations or the order in which you present them in the glTexCoord2f calls. A process of elimination might help. Verify the calcs with a small console routine and if they are correct, then think about the order in which you are presenting the the four values x1,y1,x2,y2 in your glTexCoord2f calls based on how you are rendering your mesh.

I specified the texture coordinates in the order lower-left, lower-right, upper-right, upper-left. If this resulted in the texture being upside down, then you can either flip the image data after loading and use that ordering :-), or specify the coordinates in a different order. My (0.0,0.0) is lower-left, and therefore (1.0,1.0) if upper-right. Determine wherer yours is (sketch it on paper) and once you have that, then go back to your calculations and think about the order in which they need to appear. You can work that out I think.

For my triangle strip I present them (y1,x1) and (y1,x2) - I only need two with a triangle strip (an optimisation you can think about later perhaps).

Filtering is all about the filter options you specify when you setup your texture.

Go over to NeHe and work through the tutorials - especially Lesson 6 and Lesson 7

hth
F451

[Edited by - Fahrenheit451 on March 14, 2007 10:08:48 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.