Sign in to follow this  

No texture here,Why?

This topic is 3485 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 wrote a programe to render a texture on a plane,the BMP is ok,because I have test it in NeHe's code,But I dont konw why i cant display it in my code [ source ] GLuint texture[1]; void init(char* filename) { FILE *file=NULL; assert(filename); file = fopen(filename,"r"); if ( !file ) return; fclose(file); AUX_RGBImageRec *TextureImage[1]; memset( TextureImage, 0, sizeof(void *)*1); TextureImage[0] = auxDIBImageLoad(filename); glGenTextures(1, &texture[0]); glTexImage2D( GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data ); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); if (TextureImage[0]) { if (TextureImage[0]->data) { free(TextureImage[0]->data); } free(TextureImage[0]); } // glBindTexture(GL_TEXTURE_2D, texture[0]); } void display(void) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture[0]); glBegin(GL_QUADS); glTexCoord2f(0.0f,0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); glTexCoord2f(1.0f,0.0f); glVertex3f( 1.0f,-1.0f, 0.0f); glTexCoord2f(1.0f,1.0f); glVertex3f( 1.0f, 1.0f, 0.0f); glTexCoord2f(0.0f,1.0f); glVertex3f(-1.0f, 1.0f, 0.0f); glEnd(); glFlush(); } void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 30.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0, 0.0, -3.6); } void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: exit(0); break; } } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(250, 250); glutInitWindowPosition(100, 100); glutCreateWindow(argv[0]); init("s.bmp"); glutReshapeFunc(reshape); glutDisplayFunc(display); glutKeyboardFunc (keyboard); glutMainLoop(); return 0; } [ /source ] [Edited by - Eniak19 on May 28, 2008 12:36:04 PM]

Share this post


Link to post
Share on other sites
I think you need to bind the texture before you call glTexImage2D, after glGenTextures.

P.S. Put your code inside [ source ] and [ /source ] tags for a neat scrollbox in your post.


Share this post


Link to post
Share on other sites
Quote:
Original post by deadstar
I think you need to bind the texture before you call glTexImage2D, after glGenTextures.

P.S. Put your code inside [ source ] and [ /source ] tags for a neat scrollbox in your post.

He means don't put spaces in the source tags. It should look like this:

[source]
Enter your source code here
[/source]

More info on tags

As for your question, yes, after calling glGenTextures, call glBindTexture. You have to call glBindTexture before glTexImage2D

Share this post


Link to post
Share on other sites

This topic is 3485 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this