Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (404)
games submitted by our members
Games in WIP (289)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Texture problem help needed  (Read 1617 times)
0 Members and 1 Guest are viewing this topic.
Offline Onkas81

Junior Newbie





« Posted 2010-11-03 19:21:09 »

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
Offline gouessej

JGO Ninja


Medals: 33
Projects: 1


TUER


« Reply #1 - Posted 2010-11-03 20:45:24 »

Hi!

Do you use glCullFace anywhere?

You should ask your questions here:
http://jogamp.org/forum.html

Offline Onkas81

Junior Newbie





« Reply #2 - Posted 2010-11-03 22:11:38 »

No but i don't know how to use it.
What is this method about?
Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline Onkas81

Junior Newbie





« Reply #3 - Posted 2010-11-03 22:34:04 »

I solved my problem with this:


// lets place the sarting point of cards on the draw stack
        gl.glTranslatef(1.9F, 12.4F, 0F);

      gl.glEnable(GL.GL_CULL_FACE);

       //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.glCullFace(GL.GL_FRONT);
       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.glCullFace(GL.GL_BACK);
       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();








Anyway thanks for help!!!
Offline Mickelukas

JGO Ninja


Medals: 39
Projects: 2


Java guru wanabee


« Reply #4 - Posted 2010-11-04 08:23:03 »

You should ask your questions here:
http://jogamp.org/forum.html

Sorry for asking but, how come? It's a pretty generic OpenGL question and I don't think you should send everyone away from JG any less than all people using the other libraries should...

Mike

Offline gouessej

JGO Ninja


Medals: 33
Projects: 1


TUER


« Reply #5 - Posted 2010-11-04 14:18:19 »

Anyway thanks for help!!!
Ok that is what I meant, the use of glCullFace has solved your problem Smiley

Sorry for asking but, how come? It's a pretty generic OpenGL question and I don't think you should send everyone away from JG any less than all people using the other libraries should...

Mike
It is a pretty generic OpenGL question asked into the JOGL section. If he has a specific problem with JOGL, more people will answer on the official forum of JogAmp than here. Sorry to tell you this but I don't mind people using the other OpenGL binding as we are in the JOGL section.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (32 views)
2013-05-17 21:29:12

alaslipknot (40 views)
2013-05-16 21:24:48

gouessej (70 views)
2013-05-16 00:53:38

gouessej (69 views)
2013-05-16 00:17:58

theagentd (78 views)
2013-05-15 15:01:13

theagentd (73 views)
2013-05-15 15:00:54

StreetDoggy (113 views)
2013-05-14 15:56:26

kutucuk (137 views)
2013-05-12 17:10:36

kutucuk (137 views)
2013-05-12 15:36:09

UnluckyDevil (145 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.124 seconds with 21 queries.