OpenGL Dual Textures

This is a discussion on OpenGL Dual Textures within the Game Programming forums, part of the General Programming Boards category; In the OpenGL tutorials on nehe.gamedev.net they don't tell you how to load multiple textures. I've been experimenting with the ...

  1. #1
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Question OpenGL Dual Textures

    In the OpenGL tutorials on nehe.gamedev.net they don't tell you how to load multiple textures. I've been experimenting with the original code to do this but I just can't figure out how to do this yet. Anybody know?

  2. #2
    Shadow12345
    Guest
    Umm I'm assuiming you're doing lesson 4 or 5 or whatever the first texture example is. If that's the case they do tell you how to load multiple textures. I'm assuimg you have the same setup as nehe. create a global GLuint texture array, and call the LoadTexture function for each element of that array. When you go to draw, call glBindTexture(GL_TEXTURE_2D, texture[x]); before you draw the polygon and make sure it is outside of the glBegin/glEnd block;

    Code:
    GLuint texture[2];  //storage for 2 textures
    
    ...
    //in your initialize function (InitGL() in nehe)
    texture[0] = LoadTextures("crap.bmp"); //this function name may be different than nehe's but they are fundamentally the same
    texture[1] = LoadTextures("bitmap.bmp");
    ...
    //in your drawglscene function (DrawGLScene() in nehe)
    int DrawGLScene(GLvoid)									// Here's Where We Do All The Drawing
    {
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer
    	glLoadIdentity();									// Reset The Current Modelview Matrix
    	gluLookAt(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -150.0f, 0.0f, 1.0f, 0.0f);
    	
    
    	glPushMatrix();
    	glTranslatef(-20.0f, 0.0f, 0.0f);
    	glBindTexture(GL_TEXTURE_2D, texture[0]);	//MAKES THIS OUR CURRENT TEXTURE
    	glBegin(GL_QUADS);
    	glTexCoord2f(0.0f, 0.0f);	glVertex3f(-15.0f, -5, -75.0f);
    	glTexCoord2f(1.0f, 0.0f);	glVertex3f(15.0, -5, -75.0f);
    	glTexCoord2f(1.0f, 1.0f);	glVertex3f(15.0, 5, -75);
    	glTexCoord2f(-1.0f, 1.0f);	glVertex3f(-15.0f, 5, -75);
    	glEnd();
    	glPopMatrix();
    
    	glPushMatrix();
    	glBindTexture(GL_TEXTURE_2D, texture[1]);
    	glBegin(GL_QUADS);
    	glTranslatef(20.0f, 0.0f, 0.0f);
    	glTexCoord2f(0.0f, 0.0f);	glVertex3f(-15.0f, -5, -75.0f);
    	glTexCoord2f(1.0f, 0.0f);	glVertex3f(15.0, -5, -75.0f);
    	glTexCoord2f(1.0f, 1.0f);	glVertex3f(15.0, 5, -75);
    	glTexCoord2f(-1.0f, 1.0f);	glVertex3f(-15.0f, 5, -75);
    	glEnd();
    
    
    	return TRUE;										// Everything Went OK
    }

  3. #3
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    ..

    Thank you so much.

  4. #4
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    ..

    Didn't work, here's the source:
    Attached Files Attached Files

  5. #5
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    ?

    ?

  6. #6
    Shadow12345
    Guest
    here is that example, sorry it took so long
    Attached Files Attached Files

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL Textures Disappear after SDL_VIDEORESIZE
    By ThLstN in forum Game Programming
    Replies: 3
    Last Post: 08-31-2008, 03:50 PM
  2. Multiple textures in OpenGL...
    By yaya in forum Game Programming
    Replies: 1
    Last Post: 02-12-2008, 08:24 AM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 01:34 PM
  4. OpenGL, loading BMP Textures?
    By Zeusbwr in forum Game Programming
    Replies: 12
    Last Post: 12-09-2004, 05:16 PM
  5. OpenGL / Moveing textures?
    By Oluf in forum Game Programming
    Replies: 7
    Last Post: 06-08-2004, 02:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21