Jump to content
  • Advertisement
Sign in to follow this  
tjrr3d

Texturing problem

This topic is 4462 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 have been working on this problem literally over 12 hours now, and I can not fuigure it out. The problem is that my qauads aren't being textured like I tell them to. In fact they're not getting texturedagt all!. Here my code:
GLuint base, texture;
AUX_RGBImageRec *TextImg;

Text::LoadTextImg(LPWSTR path)
{
	TextImg = auxDIBImageLoad(path);

	glGenTextures(1, &texture);
	glBindTexture(GL_TEXTURE_2D, texture);
        glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TextImg->sizeX, TextImg->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextImg->data);
	free(TextImg->data);
	free(TextImg);

	glDisable(GL_DEPTH_TEST);
	glEnable(GL_TEXTURE_2D);
}

Text::Render()
{
        glEnable(GL_TEXTURE_2D);

	// Set projection matrix to orthographic
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glOrtho(0, ScreenWidth, 0, ScreenHeight, -1, 1);

	// Move to starting position
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();
        glTranslated(x,y);
	glBindTexture(GL_TEXTURE_2D, texture);	// Make sure right texture is selected
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f);	glVertex2i(0,0);
		glTexCoord2f(1.0f, 0.0f);	glVertex2i(256,0);
		glTexCoord2f(1.0f, 1.0f);	glVertex2i(256,256);
		glTexCoord2f(0.0f, 1.0f);	glVertex2i(0,256);
	glEnd();

	// Go back to original matricies
	glPopMatrix();
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();

	glEnable(GL_DEPTH_TEST);
	glDisable(GL_TEXTURE_2D);
}




I think there is a flag or something that I'm not setting because the only thing that ever comes up is the quad, but its all white. Here's my initgl function:
QGLWidget::initializeGL()
{
  glClearColor(0.0, 0.0, 0.3, 0.0);
  glShadeModel(GL_SMOOTH);
  glEnable(GL_DEPTH_TEST);
  glClearDepth(1.0f);
}




Someone please help. [Edited by - tjrr3d on April 1, 2006 10:08:42 PM]

Share this post


Link to post
Share on other sites
Advertisement
That is probably because you clal glDIsable(GL_TEXTURE_2D) in the render function. So as soon as the render function is called once it disables texturing. Now you don't have a enable texture to set the state - so your quads will no longer render textured.

The easy fix is to enable texturing at that start of rendering

Share this post


Link to post
Share on other sites
Sorry bout that. glEnable(GL_TEXTURE_2D) was originally in there, I guess it got removed while editing. I have made the change. Either way it still doesn't work and I just see the color of the object and not the texture.

Share this post


Link to post
Share on other sites
Don't see a problem with your code. But you might want to check the value of texture if it is 0, negative or something else. If its 0 then the texture never got made. It should be a meaningful value but not 0 or some vaguely large value.

Share this post


Link to post
Share on other sites
Thats why Im so confused. The value is not zero. But I just see nom texture. I wonder if it is a Qt Problem. That is I am using Qt 4.1 (Evaluation) with the .NET 2003 integration. Man this is really getting to me.

Share this post


Link to post
Share on other sites
Yes, 256x256. This is verified when I look at TextImg->sizeX & TextImg->sizeY. I put the exact code in SDL and everything worked fine so it must be a Qt problem. Qt offers some methods for binding textures, but either they also don't work, or I'm doing something wrong, because even with Qt's built in functions, I only see white, no texture.

Share this post


Link to post
Share on other sites
Have you obtained a valid OpenGL context before you try to create your texture?

Σnigma

Share this post


Link to post
Share on other sites
I'm not sure. How can I find this out. I can draw points quads etc. if that helps. I just can't see any texture on the quads that are drawn.

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!