Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  LWGL getFloatv usage?  (Read 2422 times)
0 Members and 1 Guest are viewing this topic.
Offline Captain-Goatse

Junior Member




I suck at teh 2D. XBOX IS BIG LOL!111


« Posted 2003-01-29 08:45:10 »

I'm implementing my Occulsion/View Frustum Culling on LWGL, but I can't seem to figure out how gl.getFloatv works.

It returns ints, which I believe connect somehow to Matrix4f and the float values m04 and so on.

Now my problem is, is there any way to load from getFloatv directly into Matrix4f? I can't figure out how those ints in the docs work, and I scanned through all the significant documents and found nothing. Chman's site seems to be down.

Offline princec

JGO Kernel


Medals: 378
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2003-01-29 09:23:10 »

No, there's no way to do it directly sadly.

glFloatv returns nothing but it takes a pointer - to a direct floatbuffer no less - from which you can load the Matrix4f.

1  
2  
3  
4  
FloatBuffer fb = ByteBuffer.allocateDirect(16 * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
gl.getFloatv(GL.PROJECTION_MATRIX, Sys.getDirectBufferAddress(fb));
Matrix4f projectionMatrix = new Matrix4f();
projectionMatrix.load(fb);


or something like that. Don't forget to cache everything.

Edit: updated the example to say 16 * 4 as elias points out below, it's in bytes not floats Embarrassed

Cas Smiley

Offline Captain-Goatse

Junior Member




I suck at teh 2D. XBOX IS BIG LOL!111


« Reply #2 - Posted 2003-01-29 10:28:06 »

What exactly do you mean by cahce everything?

That code doesn't work as it is, so perpahs I should learn this NIO stuff from the beginning. If I use get() on the fb I get float number around 1.8f, but every time I get BufferUnderflowException. Should I have some sort of loop, which gives me all of the numbers in the proj matrix?

I'm basically step dancing on this ice right here, obviously I don't understand this whole thing. Can someone point me to a float buffer tutorial?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline elias

Senior Member





« Reply #3 - Posted 2003-01-29 19:24:15 »

I think that it's ByteBuffer.allocateDirect(16*4), not 16. It's counting in bytes afaik.

- elias

Offline Captain-Goatse

Junior Member




I suck at teh 2D. XBOX IS BIG LOL!111


« Reply #4 - Posted 2003-01-30 06:53:24 »

Hmm...

it doesn't work with *4 either... when I set it to 8 it works, but my matrix is empty... Now what exactly does the load function do? It doesn't set the matrix values doesn't it?

my code
           FloatBuffer fb = ByteBuffer.allocateDirect(16*Cool.order(ByteOrder.nativeOrder()).asFloatBuffer();
           gl.getFloatv(GL.PROJECTION_MATRIX, Sys.getDirectBufferAddress(fb));
           System.out.println(fb.get(gaybuffer));
           Matrix4f projectionMatrix = new Matrix4f();
           
           projectionMatrix.load(fb);
           System.out.println(projectionMatrix.m00 + "," + projectionMatrix.m01 + "," + projectionMatrix.m02 + "," + projectionMatrix.m03);
Offline princec

JGO Kernel


Medals: 378
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #5 - Posted 2003-01-30 14:42:02 »

The gl function requires just a pointer to a bit of memory - we've reserved just enough to fit 16 floats in (64 bytes) and wrapped it for Java's sake with FloatBuffer.

The glGetFloatfv function copies the data directly into the memory you've specified. From there, it's not much use.

The matrix load() function reads from the FloatBuffer at its current position. If you go doing a get() beforehand you'll advance the position by 1 float and screw it up; you'd have to do a rewind() on the buffer to put it back at the beginning - that's how Buffers work in Java: they maintain a current position at which the next read or write will occur with put() and get().

Note that wrapping buffers up with asFloatBuffer() creates a direct view of the original data but maintains an independent position.

Get a good read of the Java docs on NIO buffers.

Cas Smiley

Offline Captain-Goatse

Junior Member




I suck at teh 2D. XBOX IS BIG LOL!111


« Reply #6 - Posted 2003-01-31 08:03:02 »

Thanks cas... your sheer of knowledge is insane.


I think I got it,  thank god its weekend so I can concentrate on java 100%.
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.

BurntPizza (12 views)
2014-09-21 02:42:18

BurntPizza (11 views)
2014-09-21 01:30:30

moogie (13 views)
2014-09-21 00:26:15

UprightPath (23 views)
2014-09-20 20:14:06

BurntPizza (27 views)
2014-09-19 03:14:18

Dwinin (40 views)
2014-09-12 09:08:26

Norakomi (70 views)
2014-09-10 13:57:51

TehJavaDev (96 views)
2014-09-10 06:39:09

Tekkerue (49 views)
2014-09-09 02:24:56

mitcheeb (70 views)
2014-09-08 06:06:29
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!