Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


OpenGL OpenGL texture Mapping

This topic is 5662 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

Hye , i am kind of new to open gl and i cant get texture mapping to work properly. Instead of textured polygons i get a pixely mess. I load my textures with a function i wrote similar to NEHE''s loadbmp in chapter 6. Any ideas of whats wrong? //Some code unsigned int ogl_textures[MAX_TEXTURES]; int ogl_tex_no = 0; typedef AUX_RGBImageRec OGL_IMAGE; int map[MAP_X_SIZE*MAP_Y_SIZE] = {1,1,1,1, 1,0,0,1, 1,0,0,1, 1,0,0,1, 1,1,1,1}; OGL_IMAGE *ogl_load_bitmap(LPSTR file_name) { FILE *fp; fp=fopen(file_name,"rb"); if(fp==NULL) { return NULL; } else { fclose(fp); return auxDIBImageLoad(file_name); } } //========================================================== void ogl_init_texturing(void) { glEnable(GL_TEXTURE_2D); glGenTextures(MAX_TEXTURES,ogl_textures); ogl_tex_no = 0; } //========================================================== int ogl_bind_texture(OGL_IMAGE *image) { if(ogl_tex_no < MAX_TEXTURES) { glBindTexture(GL_TEXTURE_2D,ogl_textures[ogl_tex_no]); glTexImage2D(GL_TEXTURE_2D,0,3,image->sizeX,image->sizeY,0,GL_RGB,GL_UNSIGNED_BYTE,&image->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); ogl_tex_no++; return 1; } return 0; } //=========================================================== void ogl_switch_texture(int num) { glBindTexture(GL_TEXTURE_2D,ogl_textures[num]); } //=========================================================== //A bit of initialzation ogl_init_texturing(); if((game_textures[0]=ogl_load_bitmap("rock.bmp")) == NULL){exit(1);} if((game_textures[1]=ogl_load_bitmap("grass.bmp"))== NULL){exit(1);} if((ogl_bind_texture(game_textures[0]))==0){ exit(1);} if((ogl_bind_texture(game_textures[1]))==0){ exit(1);} //=============================================== void draw_map(void) { int dx,dy,col; float sp=1.0; glColor3ub(255,255,255); glBegin(GL_QUADS); for(dy=0;dy

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!