Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (683)
Games in Android Showcase (196)
games submitted by our members
Games in WIP (751)
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  
  Matrix4f and glLoadMatrix  (Read 4699 times)
0 Members and 1 Guest are viewing this topic.
Offline Grandmaster B

Junior Newbie

« Posted 2008-08-10 20:52:40 »


do i need to store the Matrix in a FloatBuffer before i can upload it to OpenGL? It seems a bit cumbersome to me.
It would be nice if someone could post an example, i'm new to Java...

Thanks in advance
Offline StrideColossus
« Reply #1 - Posted 2008-08-18 11:04:15 »

I've never had to set the matrix as such, generally you manipulate it rather than set it using glMatrixMode(), glLoadIdentity(), glTranslate(), glRotate(), glPushMatrix() and glPopMatrix().

If you need to get the matrices (for ray projection for example), then you do need to use a nasty NIO buffer.

This is the code I use:

     private final FloatBuffer buffer = EngineUtil.createBuffer( 16 );

    * @return Current modelview matrix (column-major)

   public Matrix getModelviewMatrix() {
      return getMatrix( GL11.GL_MODELVIEW_MATRIX );
    * @return Current projection matrix (column-major)

   public Matrix getProjectionMatrix() {
      return getMatrix( GL11.GL_PROJECTION_MATRIX );
    * Retrieves the specified matrix.
    * @param name Matrix name

   private Matrix getMatrix( int name ) {
      // Retrieve specified matrix buffer
      GL11.glGetFloat( name, buffer );
      // Convert to array
      final float[] array = new float[ 16 ];
      buffer.get( array );
      // Convert to matrix
      return new Matrix( array );

Hope this helps.
Offline Grandmaster B

Junior Newbie

« Reply #2 - Posted 2008-08-18 16:06:43 »

Thanks this gives me some clues!

I still wonder why the Matrix class isnt integrated into the LWJGL OpenGL API. For example, theres no glLoadMatrix(Matrix) method. Im used to manipulate matrices directly and then upload the result to OpenGL with glMultMatrix() or glLoadMatrix().
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline darkprophet

Senior Devvie

Go Go Gadget Arms

« Reply #3 - Posted 2008-08-18 16:42:48 »

glLoadMatrix is generally more performant then multiple JNI native calls that you oncurr with glRotate, glScale and glTransform. It also gives you the opportunity to manipulate the matrices how you see fit using methods other than what GL has integrated in it.

The reason it doesn't have a Matrix class is because it is not a game engine. LWJGL provides an interface to OpenGL and stays true to that. OpenGL takes a pointer to the array of floats representing a matrix, teh equivilant to that in Java is a FloatBuffer (there are reasons for using Buffers and not arrays).

I would suggest you grab vecmath from and start experimenting with that.

DP Smiley

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline Grandmaster B

Junior Newbie

« Reply #4 - Posted 2008-08-19 00:24:08 »

Thanks for your explanation. I'll give vecmath a try.
Offline gouessej
« Reply #5 - Posted 2008-08-19 20:51:48 »

Thanks for your explanation. I'll give vecmath a try.
vecmath :s Take care of your performance  Angry

Offline jezek2
« Reply #6 - Posted 2008-08-19 21:10:25 »

vecmath :s Take care of your performance  Angry

How so? It works well for me and I don't see reason for performance problems in it's design. Only matrix invert() is producing some memory garbage,  but that's not usually called often.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

orrenravid (204 views)
2016-07-16 03:57:23

theagentd (276 views)
2016-07-11 14:28:54

Hydroque (361 views)
2016-07-06 05:56:57

Hydroque (516 views)
2016-07-03 08:52:54

GrandCastle (386 views)
2016-07-01 09:13:47

GrandCastle (380 views)
2016-07-01 09:09:45

CopyableCougar4 (433 views)
2016-06-25 16:56:52

Hydroque (410 views)
2016-06-22 02:17:53

SwampChicken (375 views)
2016-06-20 13:22:57

SwampChicken (301 views)
2016-06-20 13:22:49
Making a Dynamic Plugin System
by Hydroque
2016-06-25 00:13:25

Java Data structures
by BinaryMonkL
2016-06-13 21:22:09

Java Data structures
by BinaryMonkL
2016-06-13 21:20:42

FPS Camera Tutorial
by Hydroque
2016-05-22 05:40:58

Website offering 3D Models specifically for games for free
by vusman
2016-05-18 17:23:09

Website offering 3D Models specifically for games for free
by vusman
2016-05-09 08:50:56

Website offering 3D Models specifically for games for free
by vusman
2016-05-06 11:10:21

Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17 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!