Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (601)
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] Issue with face culling  (Read 569 times)
0 Members and 1 Guest are viewing this topic.
Offline DazKins
« Posted 2013-06-03 18:54:05 »

How can i make sure in OpenGL the correct sides of the face are culling

My code to enable culling :

1  
2  
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glCullFace(GL11.GL_FRONT);


My issue is, is that this works fine for the top, left, right, front and back faces, but the bottom face it culls the wrong side, so the face can be seen when inside the cube not outside.

Quick note : I'm using VBOs so manually using something like this :

1  
GL11.glFrontFace(GL11.GL_CW);

(I think that's the correct function)

I don't think would be possible

DazKins

Check out my Dev Blog: http://dazkins.tumblr.com
Offline RobinB

JGO Ninja


Medals: 44
Projects: 1
Exp: 3 years


Spacegame in progress


« Reply #1 - Posted 2013-06-03 19:03:44 »

Then your probably rendering the bottom the wrong way.
Just render it backwards?
Offline DazKins
« Reply #2 - Posted 2013-06-03 19:06:45 »

How do you mean render it backwards, here is my code :

1  
2  
3  
4  
5  
6  
   public static void addCubeBottomFace(BufferObject v, float x, float y, float z) {
      v.addVertex(x, y + 1, z + 1, 0, 1);
      v.addVertex(x + 1, y + 1, z + 1, 1, 1);
      v.addVertex(x + 1, y + 1, z, 1, 0);
      v.addVertex(x, y + 1, z, 0, 0);
   }

DazKins

Check out my Dev Blog: http://dazkins.tumblr.com
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Longor1996
« Reply #3 - Posted 2013-06-03 19:22:57 »

How do you mean render it backwards, here is my code :

1  
2  
3  
4  
5  
6  
   public static void addCubeBottomFace(BufferObject v, float x, float y, float z) {
      v.addVertex(x, y + 1, z + 1, 0, 1);
      v.addVertex(x + 1, y + 1, z + 1, 1, 1);
      v.addVertex(x + 1, y + 1, z, 1, 0);
      v.addVertex(x, y + 1, z, 0, 0);
   }


Just flip the order:
1  
2  
3  
4  
5  
6  
   public static void addCubeBottomFace(BufferObject v, float x, float y, float z) {
      v.addVertex(x, y + 1, z, 0, 0);
      v.addVertex(x + 1, y + 1, z, 1, 0);
      v.addVertex(x + 1, y + 1, z + 1, 1, 1);
      v.addVertex(x, y + 1, z + 1, 0, 1);
   }


It's easy!

- Longor1996

Sorry for my bad English! That's because i am from Germany.
Offline DazKins
« Reply #4 - Posted 2013-06-03 19:24:42 »

Didn't work :S

DazKins

Check out my Dev Blog: http://dazkins.tumblr.com
Offline Longor1996
« Reply #5 - Posted 2013-06-03 20:07:55 »

Didn't work :S

How about: Try to swap the first and last vertex instructions.

1  
2  
3  
4  
5  
6  
   public static void addCubeBottomFace(BufferObject v, float x, float y, float z) {
      v.addVertex(x, y + 1, z, 0, 0);
      v.addVertex(x + 1, y + 1, z + 1, 1, 1);
      v.addVertex(x + 1, y + 1, z, 1, 0);
      v.addVertex(x, y + 1, z + 1, 0, 1);
   }


- Longor1996

Sorry for my bad English! That's because i am from Germany.
Offline DazKins
« Reply #6 - Posted 2013-06-03 20:09:48 »

Didn't work either  Huh

Could this be an issue with my graphics card? I highly doubt it myself.

DazKins

Check out my Dev Blog: http://dazkins.tumblr.com
Offline DazKins
« Reply #7 - Posted 2013-06-03 20:35:20 »

The wierd thing is, i render the top face like this :

1  
2  
3  
4  
      v.addVertex(x, y, z, 0, 0);
      v.addVertex(x + 1, y, z, 1, 0);
      v.addVertex(x + 1, y, z + 1, 1, 1);
      v.addVertex(x, y, z + 1, 0, 1);


and the bottom face like this :

1  
2  
3  
4  
      v.addVertex(x, y + 1, z, 0, 0);
      v.addVertex(x + 1, y + 1, z, 1, 0);
      v.addVertex(x + 1, y + 1, z + 1, 1, 1);
      v.addVertex(x, y + 1, z + 1, 0, 1);


The only thing different between these two faces, is the y coordinate (bearing in mind the culling of the top face works perfectly)

DazKins

Check out my Dev Blog: http://dazkins.tumblr.com
Offline DazKins
« Reply #8 - Posted 2013-06-03 20:53:52 »

hmm... another update :

I've just found that all the other faces aren't working either

Only 3 of the 6 faces work, and the ones that don't seem to be the ones with constant

y+1
y+1
y+1
y+1

x+1
x+1
x+1
x+1

z+1
z+1
z+1
z+1

DazKins

Check out my Dev Blog: http://dazkins.tumblr.com
Offline BrassApparatus

Junior Devvie





« Reply #9 - Posted 2013-06-03 20:58:59 »


It sounds to me like the problem is that you are using the same points except for your y. If you look at the winding of your top face it is fine but if you simply translate the same points downwards you are keeping the same winding. Your bottom face should have an opposite winding because you need to have all the "out" sides of your polygons facing out of the cube. You should only be able to see the "out" side of either your top face or your bottom face never bot simultaneously. (the pic shows the wrong way to do it) Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DazKins
« Reply #10 - Posted 2013-06-03 21:07:38 »

Wow, well I'm stupid.

I guess all i really needed to do was change the order of vertexes around  Undecided

Sorry for wasting everyone's time on this  Sad

Thank you for all the help though  Grin

DazKins

Check out my Dev Blog: http://dazkins.tumblr.com
Offline BrassApparatus

Junior Devvie





« Reply #11 - Posted 2013-06-03 21:15:07 »

I hope that helped. I'm new and still getting my mind wrapped around it  Grin
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.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (48 views)
2014-11-29 21:32:03

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

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

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

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
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!