Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
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 1846 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

« In padded room »



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!
Legends of Yore - The Casual Retro Roguelike
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 Mike

JGO Wizard


Medals: 69
Projects: 2
Exp: 5 years


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

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Offline gouessej

« In padded room »



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.

 

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

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (20 views)
2014-04-15 18:08:23

BurntPizza (16 views)
2014-04-15 03:46:01

UprightPath (29 views)
2014-04-14 17:39:50

UprightPath (14 views)
2014-04-14 17:35:47

Porlus (30 views)
2014-04-14 15:48:38

tom_mai78101 (55 views)
2014-04-10 04:04:31

BurntPizza (112 views)
2014-04-08 23:06:04

tom_mai78101 (212 views)
2014-04-05 13:34:39

trollwarrior1 (181 views)
2014-04-04 12:06:45

CJLetsGame (187 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!