Jump to content
  • Advertisement
Sign in to follow this  
kikkler

texturing glut primitives

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

is there a simple way to texture a primitive made by GLUT (glutSolidSphere() etc'..)? just calling glBindTexture(GL_TEXTURE_2D, textureName[whatever]) prior to drawing gives the primitive the general texture color but otherwise it's totaly flat also another more general question about texturing - currently i have a GLuint array to hold all the textures -
 GLuint textureName[n]; // storage for n texture 

and at initialization i call this function -
 glGenTextures( n, textureName ); 

and when i want to use some texture i call
 glBindTexture(GL_TEXTURE_2D, textureName[k]); 

this works but is a big confusing, as you have to remember the number for each texture instead of it's name. is there any option to do something like this ?
GLuint floorTexture, wallTexture;
glBindTexture(GL_TEXTURE_2D, wallTexture);
.
.
.
glBindTexture(GL_TEXTURE_2D, floorTexture);
.
.
.


thanks

Share this post


Link to post
Share on other sites
Advertisement
EDIT: Sorry, didn't see your first question. glBindTexture should texture map all glu and glut objects. As for it being totally flat, you might need to change from the FLAT shading model to the SMOOTH shading model:

glShadeModel(GL_SMOOTH);


end EDIT


Of course. One option (using what you have now) would be:


enum
{
WALL_TEXTURE = 0,
FLOOR_TEXTURE = 1,
/* ... */
/* could also use #define for this purpose
};

/* ... */

glBindTexture(GL_TEXTURE_2D,textureName[WALL_TEXTURE]);
/* ... */

glBindTexture(GL_TEXTURE_2D,textureName[FLOOR_TEXTURE]);
/* ... */


But if that's too confusing, you can also just symbolically name them:


GLuint wallTexture;
GLuint floorTexture;

glGenTextures(1,&wallTexture);
glGenTextures(1,&floorTexture);

/*...*/

glBindTexture(GL_TEXTURE_2D,walltexture);
/* ...*/

glBindTexture(GL_TEXTURE_2D,floorTexture);
/* ... */


which is exactly what you wanted, but it requires you recode what you've got.

Share this post


Link to post
Share on other sites
thanks for your answers

about the first question, my term "flat" was pretty inaccurate.
the primitive does get shaded, it just that you cant see the texture

shaded Sphere


anyway your suggestion doesnt seem to solve it, because iirc GL_SMOOTH is the default shader model and i didnt change it.

Share this post


Link to post
Share on other sites
of course

here's some code to demonstrate the problem
on the left i have glut sphere. on the right just a quad i specified

result
code

Share this post


Link to post
Share on other sites
That's because GLUT's geometric objects (except the teapot) don't specify texture coordinates. Either write your own routines to create them or use GLU's quadric objects. I recommend writing your own, it's not difficult and it reinforces basic math you may have forgotten (or never learned).

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!