PDA

View Full Version : Texture Object doesn't work



Limas
11-06-2010, 09:31 AM
I don't know what I should do. I tried to use Texture Objects but for some reason it doesn't work. Can anyone help me please?
Her is my code:



Texture2D tex;
GLuint texName;

...

glGenTextures(1, &texName);
glBindTexture(GL_TEXTURE_2D, texName);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex.get_width(), tex.get_height(), 0, tex.get_format(), GL_UNSIGNED_BYTE, tex.get_bits());
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

...

while( running )
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0,0, 1280,720);
glOrtho(0, 1280, 0, 720, -1,1);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.375, 0.375, 0);

glClearColor(1.0,0.6,0.2,0.0);
glClear( GL_COLOR_BUFFER_BIT );

glBindTexture(GL_TEXTURE_2D, texName);
glBegin(GL_QUADS);
glTexCoord2i(0, 0);
glVertex2i(0,0);
glTexCoord2i(0, 1);
glVertex2i(0,225);
glTexCoord2i(1, 1);
glVertex2i(300,225);
glTexCoord2i(1, 0);
glVertex2i(300,0);
glEnd();

glfwSwapBuffers();

running = !glfwGetKey( GLFW_KEY_ESC ) &&
glfwGetWindowParam( GLFW_OPENED );

}

Gardin
11-06-2010, 09:47 AM
You must set MIN_FILTER and MAG_FILTER

See: http://www.opengl.org/sdk/docs/man/xhtml/glTexParameter.xml

V-man
11-06-2010, 04:53 PM
http://www.opengl.org/wiki/Common_Mistakes#Creating_a_Texture