Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (532)
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  
  [LWJGL] 2D overlay - changing y-axis direction  (Read 4083 times)
0 Members and 1 Guest are viewing this topic.
Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Posted 2003-01-31 13:51:48 »

Topic: implementing a 2D GUI overlay.

When switching to 2D drawing operations, I set up the viewing matrix with "gl.ortho(0, width, 0, height, -1, 1)".  The problem with this is that OpenGL's coordinate system will have the origin in the bottom left corner of the screen, and have the y-axis increasing upwards.  This goes against "traditional" 2D graphics systems, so I'm trying to change it.

First I tried setting up the viewing transform as "gl.ortho(0, width, height, 0, -1, 1)", but
front-facing polygons are now back-facing and don't get drawn.  Similar tricks with "gl.scaled(1, -1, 1) ; gl.translate(0, -height, 0)" or "gl.translated(width/2, height/2, 0) ; gl.rotated(180, 0, 1, 0) ; gl.rotated(180, 0, 0, 1) ; gl.translated(-width/2, -height/2, 0)" produce the same effect.

Is there any way to change the direction of the y-axis without changing the facing direction of the polygons?

Figuring there was no way to do this, I looked at ways to fix the problems it causes.  You can disable/change culling, change the winding direction to GL.CW, draw your polygons the "wrong way round", or not perform the y-axis switch and just put up with the odd coordinate system OpenGL provides.

What do you think is the "proper" solution to this problem?

Hellomynameis Charlie Dobbie.
Online princec

JGO Kernel


Medals: 340
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2003-01-31 16:50:13 »

The 'proper' solution to this is to think like a mathematician and have 0,0 as the bottom left coordinate Smiley After a while it becomes natural.

Failing that use the gl.ortho trick but gl.disable(GL.CULL_FACE) which stops the faces being culled.

Cas Smiley

Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Reply #2 - Posted 2003-02-01 11:56:29 »

Yeah, that's what I thought.  I'm trying to get things correct in my head, as there seems to be no "cute" solution to the problem.  I checked out the source code for GLUI and it seems they just draw everything backwards...  Quitters!

I'm pulling a few tricks to get all the pixels to line up correctly, and they still don't want to play ball.  It's playing hell with my eyes peering at my screen trying to work out what pixels aren't behaving this time...

Hellomynameis Charlie Dobbie.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Reply #3 - Posted 2003-02-01 23:22:05 »

Grrr... Angry

OpenGL really doesn't like doing pixel-perfect primitives, does it?  For some reason, my OpenGL implementation doesn't appear to be working quite to spec.  Although, there is a bit of wiggle room here and there so maybe it's being correct, just unhelpfully so.

Too tired right now, I'll tackle this tomorrow. :-/

Hellomynameis Charlie Dobbie.
Online princec

JGO Kernel


Medals: 340
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #4 - Posted 2003-02-01 23:59:54 »

No problems here on Nvidia drivers. Pixel perfect every time. Although I do recall some strangeness about adding 0.35f to coordinates for something but I don't bother with it.

Cas Smiley

Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Reply #5 - Posted 2003-02-02 22:13:32 »

Yeah, you can gl.translatef(0.375f, 0.375f, 0.0f) to adjust the grid slightly with respect to window coordinates.  Points can then be specified in integer coordinates (no rounding problems when they are truncated) and start and end points of lines fall within the inscribed diamonds.  It's a good trick (theoretically) but until I work out what's going wrong I'm avoiding it  - one less thing to go wrong!

This is the problem I'm having:

B
|\
| \
|  \
A   C


Whether I draw a LINE_LOOP of ABC or a LINES of ABBC, the pixel at B is not drawn.  The line AB shouldn't draw it because it doesn't *exit* the inscribed diamond.  The line BC should draw B (but not C), but it appears not to draw B at all.  Still not sure if it's my dodgy code, my dodgy graphics drivers or my dodgy hardware at the moment.  Quite infuriating!

(I'm currently trying to work out whether the implementation is allowed to miss out this pixel if one line is in y-major and the other is in x-major.  Straw grasping ahoy!)

Hellomynameis Charlie Dobbie.
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.

pw (15 views)
2014-07-24 01:59:36

Riven (14 views)
2014-07-23 21:16:32

Riven (13 views)
2014-07-23 21:07:15

Riven (15 views)
2014-07-23 20:56:16

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

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

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

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

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

Riven (50 views)
2014-07-14 18:02:53
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!