Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
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  
  Modern Opengl (4.x) unproject  (Read 539 times)
0 Members and 1 Guest are viewing this topic.
Offline jmguillemette
« Posted 2014-02-16 19:10:00 »

Ok.. so my old code used GLU unproject to transform mouse coords into world coords.

Now that i have converted to OpenGL 4.x i have run into an issue.

The param used to call unproject include the viewport matrix. I used to get this by asking opengl to return it to me.
Now it seems i will have to create the matrix my self before calling the function.

anyone ever found any documentation on how to convert your width / height into a view port matrix?

thanks
j.

-=Like a post.. give the author a medal!=-
Offline The Lion King
« Reply #1 - Posted 2014-02-17 05:08:19 »

w/2   0    w/2+x

0      h/2   h/2+y

0       0         1


the inner 2x2 matrix handles the scaling, the 3rd column handles the translation. after everything is projected its almost like having a large 2D plane. this matrix just moves along this plane and scales how big everything is (rather than scaling how big your view port is as is common in openGL, it moves the world around the camera not the camera itself).

Anyway. enjoy

"You have to want it more than you want to breath, then you will be successful"
Offline quew8

JGO Coder


Medals: 29



« Reply #2 - Posted 2014-02-17 21:24:53 »

gluUnproject() doesn't take the viewport matrix (there isn't actually any such thing as far as OpenGL is concerned), it takes the viewport parameters. ie the stuff you pass in glViewport(): x, y, width, height.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline The Lion King
« Reply #3 - Posted 2014-02-17 21:36:53 »

gluUnproject() doesn't take the viewport matrix (there isn't actually any such thing as far as OpenGL is concerned), it takes the viewport parameters. ie the stuff you pass in glViewport(): x, y, width, height.

First, the viewport transformation can be written as a matrix so there is actually such a thing. Second, he is using modern opengl and is probably trying to avoid glu calls since these calls tend to reduce freedom and control over the program. Ive never used the gluUnproject but if it doesn't take in the projection matrix as a parameter, then it probably assumes you are using the fixed function pipeline which he is not. All he is doing is multiplying the point on the window by the inverse of the viewport and the inverse of the projection. gluUnproject does the same thing in the background it just hides the matrix math from you.

"You have to want it more than you want to breath, then you will be successful"
Offline quew8

JGO Coder


Medals: 29



« Reply #4 - Posted 2014-02-17 22:25:12 »

Firstly I meant that "as far as OpenGL is concerned" there is no such thing. Ie OpenGl doesn't use a matrix. It could depending on the driver implementation but it would just be slower to use a matrix for such a consistent operation. It is always: times by a, add b. Otherwise your viewport matrix is quite right.

And jmguillemette said he is still using the gluUnproject() function he just needed a way to get the viewport.
Offline The Lion King
« Reply #5 - Posted 2014-02-17 22:30:27 »

Firstly I meant that "as far as OpenGL is concerned" there is no such thing. Ie OpenGl doesn't use a matrix. It could depending on the driver implementation but it would just be slower to use a matrix for such a consistent operation. It is always: times by a, add b. Otherwise your viewport matrix is quite right.

And jmguillemette said he is still using the gluUnproject() function he just needed a way to get the viewport.

Ah ok your right, looked up the gluUnproject method and what he was asking made a lot more sense.

"You have to want it more than you want to breath, then you will be successful"
Pages: [1]
  ignore  |  Print  
 
 

 

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

The first screenshot will be displayed as a thumbnail.

CogWheelz (10 views)
2014-07-30 21:08:39

Riven (21 views)
2014-07-29 18:09:19

Riven (14 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

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

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

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

Riven (30 views)
2014-07-23 20:56:16
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!