Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (595)
Games in Android Showcase (169)
games submitted by our members
Games in WIP (647)
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 2743 times)
0 Members and 1 Guest are viewing this topic.
Offline Captain-Goatse

Junior Devvie

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 Spiffy Duke »

Medals: 547
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.

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

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 Devvie

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 Devvie

« 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 Devvie

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

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


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));
           Matrix4f projectionMatrix = new Matrix4f();
           System.out.println(projectionMatrix.m00 + "," + projectionMatrix.m01 + "," + projectionMatrix.m02 + "," + projectionMatrix.m03);
Offline princec

« JGO Spiffy Duke »

Medals: 547
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 Devvie

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.

KaiHH (5 views)
2015-07-07 11:39:58

deepthought (54 views)
2015-06-30 15:39:44

deepthought (57 views)
2015-06-30 15:39:09

deepthought (65 views)
2015-06-30 15:36:52

Za\'Anzabar (44 views)
2015-06-29 05:44:54

TritonDreyja (50 views)
2015-06-24 17:10:40

CopyableCougar4 (52 views)
2015-06-23 00:34:45

BurntPizza (58 views)
2015-06-21 20:36:46

cookiecompiler (99 views)
2015-06-11 15:42:53

cookiecompiler (58 views)
2015-06-11 15:41:14
How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14 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‑
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!