Menu
Forums
Login | Register

Home > Forums > OpenGL ES > GL_CULL_FACE and GL_FRONT_AND_BACK Page :  1 
GL_CULL_FACE and GL_FRONT_AND_BACK
Hi

I have pbs in converting some openGL code to ES one :
I need to draw a "trièdre" (i, j, k), a triangle with a unique color, a floor with just lines (in fact sqares not filled)
and a cube with texture.

The cube with texture is ok, the trièdre also.
but the lines on the floor do not apear also with my yellow triangle nothing visible...


here are the part of code:

GLfloat Reperexyz[] = {
0.0f,0.0f,0.0f,
0.1f,0.0f,0.0f,//x
0.0f,0.0f,0.0f,
0.0f,0.2f,0.0f,//y
0.0f,0.0f,0.0f,
0.0f,0.0f,0.3f,//z
};

GLfloat RepereTriangle[] = {
0.0f, 0.0f, -0.1f,
0.086f, 0.0f, 0.05f,
-0.086f, 0.0f, 0.05f,
};
GLfloat TerrainCarre[] = {
0.0f, 0.0f, 0.0f,
0.5f, 0.0f, 0.0f,
0.5f, 0.5f, 0.0f,
0.0f, 0.5f, 0.0f,
};

GLfloat box[] = {
// FRONT
-0.5f, -0.5f, 0.5f,
0.5f, -0.5f, 0.5f,
-0.5f, 0.5f, 0.5f,
0.5f, 0.5f, 0.5f,
// BACK
-0.5f, -0.5f, -0.5f,
... (the box is the one of the tutorial, works well of course ;-)

void TGL_Form::DrawScene()
{
float deb=10.0;
int i, j, nbSubdiv=40; /* Nombre de subdivisions du maillage */
float pas=2.0*deb/nbSubdiv;

glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glEnableClientState(GL_VERTEX_ARRAY);
glEnable(GL_CULL_FACE);
glShadeModel(GL_SMOOTH);
glTranslatef(0, 0, -zpos);
glRotatef(xrot,1,0,0);
//------- point de vision
// marque "en altitude ypos" du point de vision
glColor4f(1.0f,1.0f,0.0f,1.0f);
glPushMatrix ();
glScalef(zpos*0.5,zpos*0.5,zpos*0.5);
glNormal3f(0.0f, 0.0f, 1.0f);
glVertexPointer(3, GL_FLOAT, 0, RepereTriangle);
glDrawArrays(GL_TRIANGLES, 0, 3);
glPopMatrix ();
glTranslatef(0,-yv, 0);
// marque au sol de l'ombre du point de vision
glColor4f(0.4f,0.4f,0.4f,1.0f);
glPushMatrix ();
glScalef(zpos*0.5,zpos*0.5,zpos*0.5);
glDrawArrays(GL_TRIANGLES, 0, 3);
glPopMatrix ();
//------- fin point de vision
glRotatef(yrot,0,1,0);
glTranslatef(-xv, 0, -zv);
// affiche le terrain
// glDisable(GL_CULL_FACE);
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT_AND_BACK);
glPushMatrix ();
glRotatef (-(GLfloat)90.0, (GLfloat)1.0, (GLfloat)0.0, (GLfloat)0.0);
glColor4f(0.6,0.6,0.6, 1.0f);
// glLineWidth(1.0);
for (i=0;i<nbSubdiv;i++)
for (j=0;j<nbSubdiv;j++)
{
glPushMatrix ();
glTranslatef(-deb+i*pas, -deb+j*pas, 0.0f);
glVertexPointer(3, GL_FLOAT, 0, TerrainCarre);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glPopMatrix ();
}
glPopMatrix ();
glCullFace(GL_BACK);

glRotatef (-90.0, (GLfloat)1.0, (GLfloat)0.0, (GLfloat)0.0); // repere xy au sol !

glPushMatrix (); // dessine le cube UHP
glTranslatef(0.5f, 0, 0);
glRotatef (-90.0f, 1.0f, 0.0f, 0.0f); // retourne le cube et le déplace !
glScalef (0.3f, 0.3f, 0.3f); // rapetit

glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindTexture(GL_TEXTURE_2D, texture1);
glVertexPointer(3, GL_FLOAT, 0, box);
glTexCoordPointer(2, GL_FLOAT, 0, texCoords);

glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
// FRONT AND BACK
glNormal3f(0.0f, 0.0f, 1.0f);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glNormal3f(0.0f, 0.0f, -1.0f);
glDrawArrays(GL_TRIANGLE_STRIP, 4, 4);
// LEFT AND RIGHT
glBindTexture(GL_TEXTURE_2D, textureUHPGREEN);
glNormal3f(-1.0f, 0.0f, 0.0f);
glDrawArrays(GL_TRIANGLE_STRIP, 8, 4);
glNormal3f(1.0f, 0.0f, 0.0f);
glDrawArrays(GL_TRIANGLE_STRIP, 12, 4);
// TOP AND BOTTOM
glBindTexture(GL_TEXTURE_2D, textureUHP);
glNormal3f(0.0f, 1.0f, 0.0f);
glDrawArrays(GL_TRIANGLE_STRIP, 16, 4);
glNormal3f(0.0f, -1.0f, 0.0f);
glDrawArrays(GL_TRIANGLE_STRIP, 20, 4);
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glPopMatrix ();

if (afficheRepere)
{
glLineWidth(2.0);
glColor4f(1.0,0.0,0.0,1.0f);
glVertexPointer(3, GL_FLOAT, 0, Reperexyz);
glDrawArrays(GL_LINES, 0, 2);
glColor4f(0.0,1.0,0.0,1.0f);
glDrawArrays(GL_LINES, 2, 2);
glColor4f(0.0,0.0,1.0,1.0f);
glDrawArrays(GL_LINES, 4, 2);
glLineWidth(1.0);
}

glFlush ();
glutSwapBuffers();
CalculateFrameRate();
UpDateStatusBar();
}

in fact, how to translate :
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);

and

glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
ok
I changed my way and now I am drawing lines :
glVertexPointer(3, GL_FLOAT, 0, TerrainCarre);
glDrawArrays(GL_LINE_LOOP, 0, 4);


works well, but I don't understand why we dont se the lines if it is :
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT_AND_BACK);
Hi,

glCullFace is used to specify which faces are called. For example, if you pass GL_FRONT, front facing polygons will be culled.

If you pass GL_FRONT_AND_BACK, you are telling OpenGL ES to cull both front facing and back facing polygons which will in essence render nothing.

Generally you would leave the value of this function as the default which is GL_BACK.

Regards,
Grant

Home > Forums > OpenGL ES > GL_CULL_FACE and GL_FRONT_AND_BACK Page :  1 

You need to be logged in to reply to this topic.


All Rights Reserved, © Zeus Communications, Multimedia & Development 2004-2005

Read the Disclaimer

Links