Sign in to follow this  
kikkler

texturing glut primitives

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
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
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

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