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  
  Matrix4f and glLoadMatrix  (Read 3495 times)
0 Members and 1 Guest are viewing this topic.
Offline Grandmaster B

Junior Newbie





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

Hi,

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 13: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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
     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
     buffer.rewind();
      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 18: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 Member




Go Go Gadget Arms


« Reply #3 - Posted 2008-08-18 18: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 vecmath.dev.java.net 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 02:24:08 »

Thanks for your explanation. I'll give vecmath a try.
Offline gouessej
« Reply #5 - Posted 2008-08-19 22: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 23: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.

 

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 (15 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 (30 views)
2014-07-23 21:07:15

Riven (31 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!