Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (527)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
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  
  [SOLVED]Cube is rendering faces out of order!  (Read 999 times)
0 Members and 1 Guest are viewing this topic.
Offline wessles

JGO Wizard


Medals: 74
Projects: 4
Exp: 4 years


Radirius Software


« Posted 2013-09-02 05:30:47 »



The faces are being rendered in the order that I coded them! What do I do?!

INIT CODE
1  
2  
3  
4  
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      gluPerspective(fov, aspect, near, far);
      glMatrixMode(GL_MODELVIEW);


Cube rendering code
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
glPushMatrix();
      glBegin(GL_QUADS);
      {
         glColor3f(0.0f, 1.0f, 0.0f);     // Set The Color To Green
           glVertex3f(1.0f, 1.0f, -1.0f);   // Top Right Of The Quad (Top)
           glVertex3f(-1.0f, 1.0f, -1.0f);  // Top Left Of The Quad (Top)
           glVertex3f(-1.0f, 1.0f, 1.0f);   // Bottom Left Of The Quad (Top)
           glVertex3f(1.0f, 1.0f, 1.0f);    // Bottom Right Of The Quad (Top)

           glColor3f(1.0f, 0.5f, 0.0f);     // Set The Color To Orange
           glVertex3f(1.0f, -1.0f, 1.0f);   // Top Right Of The Quad (Bottom)
           glVertex3f(-1.0f, -1.0f, 1.0f);  // Top Left Of The Quad (Bottom)
           glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Left Of The Quad (Bottom)
           glVertex3f(1.0f, -1.0f, -1.0f);  // Bottom Right Of The Quad (Bottom)

           glColor3f(1.0f, 0.0f, 0.0f);     // Set The Color To Red
           glVertex3f(1.0f, 1.0f, 1.0f);    // Top Right Of The Quad (Front)
           glVertex3f(-1.0f, 1.0f, 1.0f);   // Top Left Of The Quad (Front)
           glVertex3f(-1.0f, -1.0f, 1.0f);  // Bottom Left Of The Quad (Front)
           glVertex3f(1.0f, -1.0f, 1.0f);   // Bottom Right Of The Quad (Front)

           glColor3f(1.0f, 1.0f, 0.0f);     // Set The Color To Yellow
           glVertex3f(1.0f, -1.0f, -1.0f);  // Bottom Left Of The Quad (Back)
           glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Right Of The Quad (Back)
           glVertex3f(-1.0f, 1.0f, -1.0f);  // Top Right Of The Quad (Back)
           glVertex3f(1.0f, 1.0f, -1.0f);   // Top Left Of The Quad (Back)

           glColor3f(0.0f, 0.0f, 1.0f);     // Set The Color To Blue
           glVertex3f(-1.0f, 1.0f, 1.0f);   // Top Right Of The Quad (Left)
           glVertex3f(-1.0f, 1.0f, -1.0f);  // Top Left Of The Quad (Left)
           glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Left Of The Quad (Left)
           glVertex3f(-1.0f, -1.0f, 1.0f);  // Bottom Right Of The Quad (Left)

           glColor3f(1.0f, 0.0f, 1.0f);     // Set The Color To Violet
           glVertex3f(1.0f, 1.0f, -1.0f);   // Top Right Of The Quad (Right)
           glVertex3f(1.0f, 1.0f, 1.0f);    // Top Left Of The Quad (Right)
           glVertex3f(1.0f, -1.0f, 1.0f);   // Bottom Left Of The Quad (Right)
           glVertex3f(1.0f, -1.0f, -1.0f);  // Bottom Right Of The Quad (Right)
      }
      glEnd();
      glPopMatrix();

Offline HeroesGraveDev

JGO Kernel


Medals: 300
Projects: 11
Exp: 3 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #1 - Posted 2013-09-02 05:36:41 »

1  
2  
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);


Add it to your GL initialisation.

Offline Simba Productions

Senior Newbie


Medals: 1



« Reply #2 - Posted 2013-09-02 05:37:30 »

This form of OpenGL rendering is very, very deprecated.

anyway add

glEnable(GL_DEPTH_TEST);


with your init calls and make sure your


   glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

edit: beat me to it Smiley still make sure your glClear is right
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline wessles

JGO Wizard


Medals: 74
Projects: 4
Exp: 4 years


Radirius Software


« Reply #3 - Posted 2013-09-02 05:39:18 »

What form should I use?!

Offline wessles

JGO Wizard


Medals: 74
Projects: 4
Exp: 4 years


Radirius Software


« Reply #4 - Posted 2013-09-02 05:39:45 »

Oh, and none of your guys' worked. Same results.

Offline Simba Productions

Senior Newbie


Medals: 1



« Reply #5 - Posted 2013-09-02 05:40:41 »

I suggest atleast starting with vertex arrays, or VBOs

google:

vertex buffer objects

or

vertex arrays

also:

glprogramming.com/red/

(a little outdated but much better than immediate mode)
Offline HeroesGraveDev

JGO Kernel


Medals: 300
Projects: 11
Exp: 3 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #6 - Posted 2013-09-02 05:43:36 »

What does your initGL() method look like now?

Offline wessles

JGO Wizard


Medals: 74
Projects: 4
Exp: 4 years


Radirius Software


« Reply #7 - Posted 2013-09-02 05:45:31 »

Wait, should I even do what you guys are saying if I am switching to vbo?

Offline HeroesGraveDev

JGO Kernel


Medals: 300
Projects: 11
Exp: 3 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #8 - Posted 2013-09-02 05:48:05 »

Wait, should I even do what you guys are saying if I am switching to vbo?

Yes. Depth testing still applies.

Just because GL11 is deprecated doesn't mean ALL of it is deprecated.

Things like glEnable(), glDrawArrays/Elements() etc. are still used in later versions of the API.
It's just the things used only for immediate mode.

Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #9 - Posted 2013-09-02 09:11:52 »

Make sure you're requesting a depth buffer when you create your display, otherwise GL_DEPTH_TEST won't have anything to work against.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline opiop65

JGO Kernel


Medals: 159
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #10 - Posted 2013-09-02 10:18:59 »

Can we see your initialization method? It has to be the depth testing. There's no other reason its doing that.

Offline wessles

JGO Wizard


Medals: 74
Projects: 4
Exp: 4 years


Radirius Software


« Reply #11 - Posted 2013-09-02 13:55:14 »

http://pastebin.com/R39uwp3x - Main class
http://pastebin.com/w5Eisvfn - Camera class

Offline wessles

JGO Wizard


Medals: 74
Projects: 4
Exp: 4 years


Radirius Software


« Reply #12 - Posted 2013-09-02 14:38:08 »

Solved. I had my znear at 0.000000000000001, and if it is too low, it starts to be bad depth. Changed it to 0.1 and it works beutifully with this init :
1  
2  
3  
4  
5  
      glEnable(GL_DEPTH_TEST);
      glEnable(GL_DEPTH_FUNC);
      glDepthMask(true);
      glEnable(GL_DEPTH_SCALE);
      glDepthFunc(GL_LEQUAL);


Source:
http://gamedev.stackexchange.com/questions/55510/cant-get-depth-testing-to-work-cube-faces-shine-through

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.

toopeicgaming1999 (73 views)
2014-11-26 15:22:04

toopeicgaming1999 (63 views)
2014-11-26 15:20:36

toopeicgaming1999 (15 views)
2014-11-26 15:20:08

SHC (29 views)
2014-11-25 12:00:59

SHC (27 views)
2014-11-25 11:53:45

Norakomi (32 views)
2014-11-25 11:26:43

Gibbo3771 (27 views)
2014-11-24 19:59:16

trollwarrior1 (40 views)
2014-11-22 12:13:56

xFryIx (78 views)
2014-11-13 12:34:49

digdugdiggy (57 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!