Skip to main content
GameDev.net gamedev.net
🔒 Locked

Multi- texturing problem in opengl es

Started by Monika Sharma Apr 19, 2011 at 6:53 AM 7 replies 3.3k views
Original Post
Monika Sharma
Monika Sharma
[font=verdana, geneva, lucida,]
[font=verdana, geneva, lucida,]Hello ,[/font]
[font=verdana, geneva, lucida,]
[/font]
[font=verdana, geneva, lucida,]I am new in opengl . I am developing a 3D Mobile game for iPhone using opengl es 1.1 . I need to use multi-texturing on one of the objects but what I am getting is [/font]All texture mapped objects show up the same and all with a combination of my two different textures. I am not able to understand where I am wrong . Please help by providing the exact procedure for doing multi-texturing .... I am taking help from this link : [/font]
[font=verdana, geneva, lucida,] http://techconficio.ca/Blog/files/OpenGL_ES_multiTex_example.html [/font]
[font=verdana, geneva, lucida,]
[/font]
[font=verdana, geneva, lucida,]Please reply as soon as possible .[/font]
[font=verdana, geneva, lucida,]
[/font]
[font=verdana, geneva, lucida,]Thanks!![/font]
V-man
V-man
The problem is on line 98 of your code. Yes, I have special ability to locate problems on remote computers but for the simple people on this forum, perhaps you can post some details.
Monika Sharma
Monika Sharma




V-man ,

Here's my code for multitexturing . I have already created textures . When I use only one texture , then everything is fine . I meant to say , the problem is somewhere in the multi-texturing code which is given as below . I am following this link for multi-texturing : [color="#1C2837"]http://techconficio....ex_example.html .
[color="#1C2837"][size=2]


glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);

glActiveTexture(GL_TEXTURE1);
glEnable(GL_TEXTURE_2D);

glColor4f(0.0f, 0.25f, 0.25f, 0.25f);
glActiveTexture(GL_TEXTURE0);
glBindTexture( GL_TEXTURE_2D,m_mounttex ); // m_mounttex is first texture
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT , 1.0f);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

// add the m_mounttex to the constant 0.25
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD);
glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS);

// Now set the m_cameraTexture and modulate (multiply)
glActiveTexture(GL_TEXTURE1);
glBindTexture( GL_TEXTURE_2D,m_cameraTexture );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT , 1.0f);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

// Set the texture environment mode for this texture to modulate
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

// Use the previous combine texture as source 0
glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);

// Use the current texture as source 1
glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE);

//Set what we will operate on, in this case we are going to use
// just the texture colours.
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);

RenderDrawable(m_drawables.Car); //Drawing the object
glDisable(GL_TEXTURE_2D);



AndyEsser
AndyEsser
Care to show us the pertinent rendering code as well?
Monika Sharma
Monika Sharma

Care to show us the pertinent rendering code as well?



Following is my rendering code :-


void RenderingEngine::RenderDrawable(const Drawable& drawable)

{

glPushMatrix();

TMatrix matrix,matrix1;

for (int i=0; i<16; i++) {

matrix=drawable.object;

}

matrix1=camRot;

matrix1*=matrix;

GLfloat obj[16];

for (int i=0; i<16; i++) {

obj=matrix1;

}

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

glLoadMatrixf(obj);

int stride = sizeof(vec3) + sizeof(vec3) + sizeof(vec2);

const GLvoid* normalOffset = (const GLvoid*) (sizeof(vec3)+sizeof(vec2));

const GLvoid* texCoordOffset = (const GLvoid*) (sizeof(vec3));

glEnableClientState(GL_VERTEX_ARRAY);

glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glEnableClientState(GL_NORMAL_ARRAY);

glBindBuffer(GL_ARRAY_BUFFER, drawable.VertexBuffer);

glVertexPointer(3, GL_FLOAT, stride, 0);

glTexCoordPointer(2, GL_FLOAT, stride, texCoordOffset);

glNormalPointer(GL_FLOAT, stride, normalOffset);



glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, drawable.IndexBuffer);

glDrawElements(GL_TRIANGLES, drawable.IndexCount, GL_UNSIGNED_SHORT, 0);

glPopMatrix();

}



Please reply as soon as possible.
george_azure
george_azure
Try this for setting up the textures at render time:

glEnable(GL_TEXTURE_2D);
glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, m_mounttex);
glEnable(GL_TEXTURE_2D);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE);

glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D, m_cameraTexture);
glEnable(GL_TEXTURE_2D);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
RenderDrawable(m_drawables.Car); //Drawing the object
glDisable(GL_TEXTURE_2D);

This makes a simple modulation of those two textures.

Why should we play games with poor gameplay, weak AI but good graphics when we have REALITY?
V-man
V-man
Perhaps something is fudged with the driver.

Try calling glActiveTexture(GL_TEXTURE1) before calling
glDisable(GL_TEXTURE_2D);
Monika Sharma
Monika Sharma

Perhaps something is fudged with the driver.

Try calling glActiveTexture(GL_TEXTURE1) before calling
glDisable(GL_TEXTURE_2D);


I have already solved the problem that all my texture mapped objects showing up the combination of two textures by calling glActiveTexture(GL_TEXTURE1) before calling
glDisable(GL_TEXTURE_2D);

Main problem is that my car is not showing two textures. It is just showing m_mounttex texture i.e. my first texture. I want to achieve the similar effect as shown in [color="#1C2837"]http://techconficio....ex_example.html . But , I am not getting that result ....
[color="#1C2837"]Please help !!!
Monika Sharma
Monika Sharma
I have solved my problem.

Thanks all for the help !!!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.