PDA

View Full Version : how to put 2 textures onto 2 quads? any ideas



noobscratcher
03-30-2012, 05:30 AM
I'm trying to create gui.

I have 2 quads.

One with the first texture on it and one without a texture on it but with the same texture as the first one.

What I want is to be able to put 2 separate textures onto 2 separate quads?

how can this be done?

I've tried looking at the man pages and found out that I may have to use glTexCoordPointer apart from that I'm stumped :(.


here are my vertex/texture cordinates positions in a GLfloat container


I'm using GLSL 330/OpenGL 3.3



static const GLfloat GUIVertices[] = {




1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f,
-1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f,
-1.0f, 0.94f, 0.0f, 1.0f, 0.0f, 1.0f,
1.0f, 0.94f, 0.0f, 1.0f, 1.0f, 1.0f,




// x y z w X Y
1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f,
-1.0f,-1.0f, 0.0f, 1.0f, 0.0f, 0.0f,
-1.0f,-0.94f, 0.0f,1.0f, 0.0f, 1.0f,
1.0f, -0.94f, 0.0f,1.0f, 1.0f, 1.0,


};



thanks in advance

BionicBytes
03-30-2012, 08:11 AM
One with the first texture on it and one without a texture on it but with the same texture as the first one.

eh? thought you said the second didn't have a texture?

Anyway, i assume you are not actually using a shader to texture the quad but fixed functionality - despite telling us
I'm using GLSL 330

In fixed functionality you need to either render as two separate passes (dead easy by enabling blending - glenable (GL_BLEND) ) or by using multitexturing.
Here's how you can do it - notice you need to enable the second set of texture units and send in multiple texture coordinates.


glActiveTexture (GL_TEXTURE0);
glbindtexture (GL_TEXTURE0, tex1_ID);
glActiveTexture (GL_TEXTURE1);
glenable (GL_TEXTURE2D);
glbindtexture (GL_TEXTURE1, tex1_ID);


glBegin(GL_QUADS);
glMultiTexCoord2f(GL_TEXTURE0, 0, 0);
glMultiTexCoord2f(GL_TEXTURE1, 0, 0);
glVertex3f(blah0, blah0, blah0);
glMultiTexCoord2f(GL_TEXTURE0, 0, 1);
glMultiTexCoord2fGL_TEXTURE1, 0, 1);
glVertex3f(blah1, blah1, blah1);
glMultiTexCoord2(GL_TEXTURE0, 1, 1);
glMultiTexCoord2(GL_TEXTURE1, 1, 1);
glVertex3f(blah2, blah2, blah2);
glMultiTexCoord2(GL_TEXTURE0, 1, 0);
glMultiTexCoord2(GL_TEXTURE1, 1, 0);
glVertex3f(blah3, blah3, blah3);
glEnd();

glActiveTexture (GL_TEXTURE1);
gldisable (GL_TEXTURE2D);
glActiveTexture (GL_TEXTURE0);
//gldisable (GL_TEXTURE2D); //leave enabled - default state