Skip to main content
GameDev.net gamedev.net
🔒 Locked

Using textures!

Started by Trillian Jul 11, 2006 at 9:08 PM 1 replies 400+ views
Original Post
Trillian
Trillian
glEnable(GL_NEWBE); Hello! I'm currently making a comeback to opengl after about a year in directx. I didn't remember much of the API so I found myself noobified :). So, I am currently working on a very basic application that is supposed to be showing a textured quad. I got the quad part easily and I just have to map it now! I followed NeHe's tutorials for loading TGA, and I am very confident that my application is now capable of loading these files. However, the problem would be in the way I act to actually show this texture on-screen. It might also be related to device states. Anyways, here's my code :

// WinMain
glEnable(GL_TEXTURE_2D);

while(!g_Window.HasClosed())
{
	if(HandleMessages()) continue; // Handles window messages, works fine

	g_Environment.ClearColorBuffer(); // Calls ::glClear
	g_Sprite.Render(); // see further
	g_Device.SwapBuffers(); // ::calls SwapBuffers
}



// Sprite::Render()

glLoadIdentity();
glTranslatef(150.0f, 150.0f, 0.0f);
glRotatef(45.0f, 0.0f, 0.0f, 1.0f);

glBindTexture(GL_TEXTURE_2D, texid); // Texture id of loaded TGA

glBegin(GL_QUADS);

float halfwidth  = 50.0f;
float halfheight = 50.0f;

// texrect = { 0.0f, 0.0f, 1.0f, 1.0f } u1,v1,u2,v2

glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
glTexCoord2f(texrect.u1, texrect.v1); glVertex3f(-halfwidth, -halfheight, 0.0f);
glTexCoord2f(texrect.u2, texrect.v1); glVertex3f(halfwidth,  -halfheight, 0.0f);
glTexCoord2f(texrect.u2, texrect.v2); glVertex3f(halfwidth,  halfheight,  0.0f);
glTexCoord2f(texrect.u1, texrect.v2); glVertex3f(-halfwidth, halfheight,  0.0f);

glEnd();

So with this code I get a yellow rotated and translated quad, but no evidence of texture. I've tried to set it white or to omit glColor4f but I still get an untextured sprite. Can anyone help? glDisable(GL_NEWBE);
As-12
As-12
Well.. Im also newbie in OGL too. But If you loaded the image into the memory binding tex object and intialize with glTexImage2D. So Did you set the texture filtering with the currrent text object? Because I met this problem before that I loaded everything into memory and bound into tex obj. But forgot to set the texture filtering.

Heres the example of texture filter setting codes.
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteriGL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
Kalidor
Kalidor
Can you post the code where you create the texture?

Topic Locked

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

Sign in to reply to this topic.