Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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  
  [n00b] Back painted on top of front!?  (Read 1345 times)
0 Members and 1 Guest are viewing this topic.
handle0001
Guest
« Posted 2003-12-26 13:59:09 »

Hi - after following this tutorial: http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=05
(more or less), the rear of my cube consitently gets drawn in front of the front of my cube (or maybe the front is somehow transparent). Any advice would be greatly appreciated. Here is the code I am using:

import java.awt.*;
import java.awt.event.*;
import net.java.games.jogl.*;

class JOGLTest extends Frame implements GLEventListener {

     public JOGLTest () {
           super.setUndecorated(true);                                                            //Undecorated for Fullscreen mode
           super.setIgnoreRepaint(true);                                                      //Ignore Repaint for Fullscreen mode
           super.addWindowListener(new WindowAdapter() {                              //Exit on window close
                 public void windowClosing (WindowEvent we) {
                       System.exit(0);
                 }
           });

           GLCapabilities capabilities = new GLCapabilities();                        //Get GLCapabilities for GLCanvas
           GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(capabilities);      //Create GLCanvas
           canvas.addGLEventListener(this);                                                //Listen for GL Events
           super.add(canvas);                                                                        //Add canvas to frame

           GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(this);      //Set Fullscreen mode
     }

     public static void main (String args[]) {
           new JOGLTest();
     }

     public void init (GLDrawable gld) {
           GL gl = gld.getGL();
           gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
           gl.glClearDepth(8.0f);
           gl.glEnable(GL.GL_DEPTH_TEST);
     }

     public void reshape (GLDrawable gld, int x, int y, int width, int height) {
           GL gl = gld.getGL();
           GLU glu = gld.getGLU();
           gl.glViewport(0, 0, width, height);
           gl.glMatrixMode(GL.GL_PROJECTION);
           gl.glLoadIdentity();
           glu.gluPerspective(45.0,(double)width/height, 0.0, 10.0);
           gl.glMatrixMode(GL.GL_MODELVIEW);
           gl.glLoadIdentity();
     }

     public void display (GLDrawable gld) {
           GL gl = gld.getGL();
           gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
           gl.glLoadIdentity();
           gl.glTranslatef(0.0f, 0.0f, -5.0f);
           //gl.glRotatef(45.0f, 0.0f, 1.0f, 0.0f); //Reenable when cube is drawn correctly
           gl.glBegin(GL.GL_QUADS);
                 gl.glColor3f(1.0f, 1.0f, 1.0f);
                 gl.glVertex3f(1.0f, 1.0f, -1.0f);
                 gl.glVertex3f(-1.0f, 1.0f, -1.0f);
                 gl.glVertex3f(-1.0f, 1.0f, 1.0f);
                 gl.glVertex3f(1.0f, 1.0f, 1.0f);

                 gl.glColor3f(0.0f, 0.0f, 0.0f);
                 gl.glVertex3f(1.0f, -1.0f, 1.0f);
                 gl.glVertex3f(-1.0f, -1.0f, 1.0f);
                 gl.glVertex3f(-1.0f, -1.0f, -1.0f);
                 gl.glVertex3f(1.0f, -1.0f, -1.0f);

                 gl.glColor3f(0.0f, 0.0f, 1.0f);
                 gl.glVertex3f(1.0f, 1.0f, 1.0f);
                 gl.glVertex3f(-1.0f, 1.0f, 1.0f);
                 gl.glVertex3f(-1.0f, -1.0f, 1.0f);
                 gl.glVertex3f(1.0f, -1.0f, 1.0f);

                 gl.glColor3f(1.0f, 0.0f, 0.0f);
                 gl.glVertex3f(1.0f, -1.0f, -1.0f);
                 gl.glVertex3f(-1.0f, -1.0f, -1.0f);
                 gl.glVertex3f(-1.0f, 1.0f, -1.0f);
                 gl.glVertex3f(1.0f, 1.0f, -1.0f);

                 gl.glColor3f(0.0f, 1.0f, 0.0f);
                 gl.glVertex3f(-1.0f, 1.0f, 1.0f);
                 gl.glVertex3f(-1.0f, 1.0f, -1.0f);
                 gl.glVertex3f(-1.0f, -1.0f, -1.0f);
                 gl.glVertex3f(-1.0f, -1.0f, 1.0f);

                 gl.glColor3f(0.5f, 0.5f, 0.5f);
                 gl.glVertex3f(1.0f, 1.0f, -1.0f);
                 gl.glVertex3f(1.0f, 1.0f, 1.0f);
                 gl.glVertex3f(1.0f, -1.0f, 1.0f);
                 gl.glVertex3f(1.0f, -1.0f, -1.0f);

           gl.glEnd();

     }

     public void displayChanged (GLDrawable gld, boolean modeChanged, boolean deviceChanged) {
     }
}
Offline Yuri Vl. Gushchin

Senior Member




Speak Java!


« Reply #1 - Posted 2003-12-26 14:50:10 »

I think the problem is face winding you use. So, I can suggest for testing the following steps:

1. Try to disable face culling be call
  gl.glDisable(GL.GL_CULL_FACE)
just before your glBegin(...)

2. Revert changes back and try to change face culling mode to GL_BACK:
  gl.glEnable(GL.GL_CULL_FACE)
  gl.glCullFace(GL.GL_FRONT);

3. Revert changes back and try to change the winding mode from counterclockwise (default) to clockwise:
  gl.glFrontFace(GL.GL_CW);

4. Revert changes back and try to reverse the order of vertexes in every quad you feed to OpenGL.

Yuri

Yuri Vl. Gushchin
JProof Group
handle0001
Guest
« Reply #2 - Posted 2003-12-26 15:28:38 »

Thanks for the advice! Unfortunately, none of it worked  :-/.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
handle0001
Guest
« Reply #3 - Posted 2003-12-26 17:20:35 »

Interestingly, when I make the blue front quad the first one and change the glTransfrom -6 on the z axis, it draws it correctly (can't see throught the blue front).

However, when the above-mentioned changes are made, other sides are not drawn once the cube is rotated.  I don't get it.  Huh
handle0001
Guest
« Reply #4 - Posted 2003-12-26 17:47:58 »

My inexperience becomes more obvious with each post Smiley. Turns out this program works fine if I just change one line.

glu.gluPerspective(45.0,(double)width/height, 0.0, 10.0);

should be

glu.gluPerspective(45.0,(double)width/height, 1.0, 10.0);

Could someone please give me an explanation of what this actually does?
Offline NexusOne

Junior Member




Java games rock!


« Reply #5 - Posted 2003-12-30 01:13:39 »

um, i'm somewhat new at this but I think the number you changed was the z-coordinate of the closest points that will be rendered (10 being the z-coordinate of the furthest points, outside that range things just won't be drawn). I could be confusing this with something else but I think that's it.

btw, u know, u don't have u type "super" in front of your methods unless you've overwritten them with methods of the same name in your class.

let's see if 50 posts makes me a "junior member"...
(edit) guess not.
handle0001
Guest
« Reply #6 - Posted 2003-12-30 15:26:10 »

Thanks a lot, NexusOne.
(BTW, the super is there for clarification for myself - I think its more readable that way)
Offline NexusOne

Junior Member




Java games rock!


« Reply #7 - Posted 2004-01-01 03:38:20 »

n/p

turns out i am a junior member now... sweeeet
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.

ctomni231 (34 views)
2014-07-18 06:55:21

Zero Volt (30 views)
2014-07-17 23:47:54

danieldean (25 views)
2014-07-17 23:41:23

MustardPeter (27 views)
2014-07-16 23:30:00

Cero (42 views)
2014-07-16 00:42:17

Riven (44 views)
2014-07-14 18:02:53

OpenGLShaders (32 views)
2014-07-14 16:23:47

Riven (31 views)
2014-07-14 11:51:35

quew8 (30 views)
2014-07-13 13:57:52

SHC (66 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!