Jump to content
  • Advertisement
Sign in to follow this  
Eniak19

No texture here,Why?

This topic is 3676 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
Advertisement
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
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!