mapping 2 different textures
The same way you map 1 texture to 1 object... please explain what you are trying to do more clearly
i have several objects drawn in my display function. i want to map a texture to the first quad i draw, and another texture to the second quad etc.
how do switch textures?
how do switch textures?
When you want to change texture to use. For example, in the display function.
Or however you deraw your objects. Replace the glBegin/glEnd pairs with whatever you use to draw the objects.
glBindTexture(GL_TEXTURE_2D, firstTexture);glBegin(GL_TRIANGLES); ... vertices for first object goes hereglEnd();glBindTexture(GL_TEXTURE_2D, secondTexture);glBegin(GL_TRIANGLES); ... vertices for second object goes hereglEnd();
Or however you deraw your objects. Replace the glBegin/glEnd pairs with whatever you use to draw the objects.
Quote:Original post by prophete
that's what ive done.. its not working though. here's my code attached
... attached where?
sorry.. here's the code
[Edited by - prophete on September 8, 2006 12:57:20 PM]
#include <iostream>#include <GL/glut.h>#include "READ_BMP.h"float zoom = 15.0f;float rotx = 0;float roty = 0.001f;float tx = 0;float ty = 0;int lastx=0;int lasty=0;unsigned char Buttons[3] = {0};BYTE * grass;BYTE * wood;BYTE * sky;int image_width, image_height, width, height;float stool_width=1.1, stool_foot_height=0.6, stool_foot_width=0.2, stool_height = 2;GLuint texGrass, texSky, texSnow, texWood;//-------------------------------------------------------------------------------/// Initialises the openGL scenevoid Init() { glEnable(GL_DEPTH_TEST);}//-------------------------------------------------------------------------------/// Draws the scenevoid display(){ glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); //used for transformation of scene glLoadIdentity(); glTranslatef(0,0,-zoom); glTranslatef(tx,ty,0); glRotatef(rotx,1,0,0); glRotatef(roty,0,1,0); // draw plane glBindTexture (GL_TEXTURE_2D, texGrass); glBegin(GL_QUADS); glTexCoord2f (0, 0); glVertex3f(-10,0,-10); glTexCoord2f (0, 1); glVertex3f(-10,0,10); glTexCoord2f (1, 1); glVertex3f(10,0,10); glTexCoord2f (1, 0); glVertex3f(10,0,-10); glEnd(); glBindTexture(GL_TEXTURE_2D, texWood); glBegin(GL_QUADS); //stool foot 1 glVertex3f(0.5, 0, 0); glVertex3f (0.5 + stool_foot_width, 0, 0); glVertex3f (0.5 + stool_foot_width, 0 + stool_foot_height, 0); glVertex3f (0.5, 0 + stool_foot_height, 0); glEnd(); glBegin(GL_QUADS); //stool seat glTexCoord2f (0, 0); glVertex3f(0.5, stool_foot_height, 0); glTexCoord2f (0, 1); glVertex3f(0.5 + stool_width, stool_foot_height, 0); glTexCoord2f (1, 1); glVertex3f(0.5 + stool_width, stool_foot_height, stool_width); glTexCoord2f (1, 0); glVertex3f(0.5, stool_foot_height, stool_width); glEnd(); glBegin(GL_QUADS); //stool foot 2 glTexCoord2f (0, 0); glVertex3f (0.5 + stool_width, 0, 0); glTexCoord2f (0, 1); glVertex3f (0.5 + stool_width - stool_foot_width, 0, 0); glTexCoord2f (1, 1); glVertex3f (0.5 + stool_width - stool_foot_width, stool_foot_height, 0); glTexCoord2f (1, 0); glVertex3f (0.5 + stool_width, stool_foot_height, 0); glEnd(); glBegin(GL_QUADS); //stool foot 3 glTexCoord2f (0, 0); glVertex3f (0.5 + stool_width, 0, stool_width); glTexCoord2f (0, 1); glVertex3f (0.5 + stool_width - stool_foot_width, 0, stool_width); glTexCoord2f (1, 1); glVertex3f (0.5 + stool_width - stool_foot_width, stool_foot_height, stool_width); glTexCoord2f (1, 0); glVertex3f (0.5 + stool_width, stool_foot_height, stool_width); glEnd(); glBegin(GL_QUADS); //stool foot 4 glTexCoord2f (0, 0); glVertex3f(0.5, 0, stool_width); glTexCoord2f (0, 1); glVertex3f (0.5 + stool_foot_width, 0, stool_width); glTexCoord2f (1, 1); glVertex3f (0.5 + stool_foot_width, 0 + stool_foot_height, stool_width); glTexCoord2f (1, 0); glVertex3f (0.5, 0 + stool_foot_height, stool_width); glEnd(); glBegin(GL_QUADS); //stool back glTexCoord2f (0, 0); glVertex3f (0.5, stool_height, 0); glTexCoord2f (0, 1); glVertex3f (0.5 + stool_width, stool_height, 0); glTexCoord2f (1, 1); glVertex3f (0.5 + stool_width, stool_foot_height, 0); glTexCoord2f (1, 0); glVertex3f (0.5, stool_foot_height, 0); glEnd(); glFlush(); glutSwapBuffers();}//-------------------------------------------------------------------------------/// Called when the screen gets resized/// \param w - the new width/// \param h - the new height/// void reshape(int w, int h){ // prevent divide by 0 error when minimised if(w==0) h = 1; glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45,(float)w/h,0.1,100); glMatrixMode(GL_MODELVIEW); glLoadIdentity();}//-------------------------------------------------------------------------------//void Motion(int x,int y){ int diffx=x-lastx; int diffy=y-lasty; lastx=x; lasty=y; if( Buttons[0] && Buttons[1] ) { zoom -= (float) 0.05f * diffx; } else if( Buttons[0] ) { rotx += (float) 0.5f * diffy; roty += (float) 0.5f * diffx; } else if( Buttons[1] ) { tx += (float) 0.05f * diffx; ty -= (float) 0.05f * diffy; } glutPostRedisplay();}//-------------------------------------------------------------------------------//void Mouse(int b,int s,int x,int y){ lastx=x; lasty=y; switch(b) { case GLUT_LEFT_BUTTON: Buttons[0] = ((GLUT_DOWN==s)?1:0); break; case GLUT_MIDDLE_BUTTON: Buttons[1] = ((GLUT_DOWN==s)?1:0); break; case GLUT_RIGHT_BUTTON: Buttons[2] = ((GLUT_DOWN==s)?1:0); break; default: break; } glutPostRedisplay();}/*void tex (BYTE * texture, char* pic){ BMP_Read(pic, &texture, image_width, image_height); width = image_width; height = image_height; while (width > 1) width = width/2; while (height > 1) height = height/2; if (height!=1 || width != 1) gluScaleImage ( GL_TEXTURE_2D, image_width, image_height, GL_UNSIGNED_BYTE, &wood, image_width, image_height, GL_UNSIGNED_BYTE, &wood); glTexImage2D ( GL_TEXTURE_2D, 0, GL_RGB,image_width, image_height, 0, GL_RGB, GL_UNSIGNED_BYTE, texture);; gluBuild2DMipmaps(GL_TEXTURE_2D, 4, image_width, image_height, GL_RGB, GL_UNSIGNED_BYTE, texture); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glEnable(GL_TEXTURE_2D); }*///-------------------------------------------------------------------------------///void main(int argc,char** argv){ glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH); glutInitWindowSize(640,480); glutInitWindowPosition(100,100); glutCreateWindow("3D Scene"); Init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMouseFunc(Mouse); glutMotionFunc(Motion); BMP_Read("pics/Grass1.bmp", &grass, image_width, image_height); width = image_width; height = image_height; while (width > 1) width = width/2; while (height > 1) height = height/2; if (height!=1 || width != 1) gluScaleImage ( GL_TEXTURE_2D, image_width, image_height, GL_UNSIGNED_BYTE, &grass, image_width, image_height, GL_UNSIGNED_BYTE, &grass); glBindTexture (GL_TEXTURE_2D, texGrass); glTexImage2D ( GL_TEXTURE_2D, 0, GL_RGB,image_width, image_height, 0, GL_RGB, GL_UNSIGNED_BYTE, grass); gluBuild2DMipmaps(GL_TEXTURE_2D, 4, image_width, image_height, GL_RGB, GL_UNSIGNED_BYTE, grass); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);// tex(sky, "pics/Sky.bmp"); BMP_Read("pics/wood.bmp", &wood, image_width, image_height); width = image_width; height = image_height; while (width > 1) width = width/2; while (height > 1) height = height/2; if (height!=1 || width != 1) gluScaleImage ( GL_TEXTURE_2D, image_width, image_height, GL_UNSIGNED_BYTE, &wood, image_width, image_height, GL_UNSIGNED_BYTE, &wood); glBindTexture (GL_TEXTURE_2D, texWood); glTexImage2D ( GL_TEXTURE_2D, 0, GL_RGB,image_width, image_height, 0, GL_RGB, GL_UNSIGNED_BYTE, wood); gluBuild2DMipmaps(GL_TEXTURE_2D, 4, image_width, image_height, GL_RGB, GL_UNSIGNED_BYTE, wood); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glEnable(GL_TEXTURE_2D); glutMainLoop();}
[Edited by - prophete on September 8, 2006 12:57:20 PM]
Don't just dump code in a post like that. Formatting is screwed up among other things. Edit your code and put the code inside the source-tags. See the FAQ on how to make them. I will look at the code once you edited your post and posted the code inside those tags.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement