Hello world!!!
I have a big problem programming a card game. I want to apply two textures: one on the front of my card and another to the back of my card.
Here is my code:
// lets place the sarting point of cards on the draw stack
gl.glTranslatef(1.9F, 12.4F, 0F);
//draw
gl.glPushMatrix();
com.sun.opengl.util.texture.Texture texFrontFace = TexLoader.load(this.cardTopTexturePath);
texFrontFace.setTexParameteri(GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
texFrontFace.setTexParameteri(GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT);
TextureCoords tcFrontFace = texFrontFace.getImageTexCoords();
com.sun.opengl.util.texture.Texture texBackFace = TexLoader.load(this.cardBackTexturePath);
texBackFace.setTexParameteri(GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
texBackFace.setTexParameteri(GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT);
TextureCoords tcBackFace = texBackFace.getImageTexCoords();
float xrot= 90f;
float yrot= 180f;
float zrot= 0f;
gl.glTranslatef(0, 0, 0);
gl.glRotatef(xrot, 1.0F, 0.0F, 0.0F);
gl.glRotatef(yrot, 0.0f, 1.0f, 0.0f);
gl.glRotatef(zrot, 0.0f, 0.0f, 1.0f);
gl.glScalef(0.31F, 0.31F, 0.31F); //TOO BIG
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glEnable(GL.GL_ALPHA_TEST);
gl.glAlphaFunc(GL.GL_GREATER, 0);
gl.glEnable(GL.GL_TEXTURE_2D);
texFrontFace.bind();
// replace the quad colours with the texture
gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE,GL.GL_REPLACE);
//cardModel.opengldraw(gl);
gl.glBegin(GL.GL_QUADS);
gl.glNormal3f(0.0f, 0.0f, 1.0f);
gl.glTexCoord2f(tcFrontFace.left(), tcFrontFace.bottom());
gl.glVertex3f(-6.1f, 0f, -9f);
gl.glTexCoord2f(tcFrontFace.right(), tcFrontFace.bottom());
gl.glVertex3f(6f, 0f, -9f);
gl.glTexCoord2f(tcFrontFace.right(), tcFrontFace.top());
gl.glVertex3f(6f, 0f, 9f);
gl.glTexCoord2f(tcFrontFace.left(), tcFrontFace.top());
gl.glVertex3f(-6.1f, 0f, 9f);
gl.glEnd();
gl.glDisable(GL.GL_TEXTURE_2D);
// switch back to modulation of quad colours and texture
gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE,GL.GL_MODULATE);
gl.glDisable(GL.GL_ALPHA); // switch off transparency
gl.glDisable(GL.GL_BLEND);
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glEnable(GL.GL_ALPHA_TEST);
gl.glAlphaFunc(GL.GL_GREATER, 0);
gl.glEnable(GL.GL_TEXTURE_2D);
texBackFace.bind();
// replace the quad colours with the texture
gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE,GL.GL_REPLACE);
//cardModel.opengldraw(gl);
gl.glBegin(GL.GL_QUADS);
gl.glNormal3f(0.0f, 0.0f, -1.0f);
gl.glTexCoord2f(tcBackFace.left(), tcBackFace.bottom());
gl.glVertex3f(-6.1f, 0f, -9f);
gl.glTexCoord2f(tcBackFace.right(), tcBackFace.bottom());
gl.glVertex3f(6f, 0f, -9f);
gl.glTexCoord2f(tcBackFace.right(), tcBackFace.top());
gl.glVertex3f(6f, 0f, 9f);
gl.glTexCoord2f(tcBackFace.left(), tcBackFace.top());
gl.glVertex3f(-6.1f, 0f, 9f);
gl.glEnd();
gl.glDisable(GL.GL_TEXTURE_2D);
// switch back to modulation of quad colours and texture
gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE,GL.GL_MODULATE);
gl.glDisable(GL.GL_ALPHA); // switch off transparency
gl.glDisable(GL.GL_BLEND);
gl.glPopMatrix();
The fact is that jogl print the front face but not the back face (i see front face from each point of vue but reverse from the opposite point of vue, like if it was transparent)
Thanks for help