Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (407)
games submitted by our members
Games in WIP (293)
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  
  [SOLVED]Problem with Transformation Matrices passed into GLSL with LWJGL  (Read 2325 times)
0 Members and 1 Guest are viewing this topic.
Offline codemonkey

Senior Newbie





« Posted 2011-10-12 04:33:35 »

Hey All, I really hate to do this, but after a few hours of googling and tried to find a solution, JGO you are my last hope. As an effort to learn 3D programming with Java, I decided to port the Modern OpenGL Programming Wikibook (http://en.wikibooks.org/wiki/OpenGL_Programming#Modern_OpenGL) over to Java/LWJGL, and I'm hosting the code over at a github repo: (https://github.com/alihelmy/lwjglTutorial)

I had been going fine, until I got to lesson 4 (http://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Tutorial_04) that deals with transformation matrices and passing them as a uniform variable to vertex/fragment GLSL shaders. The code works with no errors, but there is absolutely nothing drawn on the screen.

I have tried replacing the transformation matrix with an identity matrix to no avail. Removing the glUniformMatrix4() call & transformMatrix usage in the shaders, reverts code to working correctly

You can take a look at the complete code HERE: (https://github.com/alihelmy/lwjglTutorial/tree/master/LessonFour) and for brevity, I have included here the more "important" parts IMHO

loading up of transformationMatrix attribute and preparing buffer, happens once:
      String transformMatrixAttributeName="transformMatrix";
      transformMatrixAttributeIndex=glGetUniformLocation(shaderProgram,transformMatrixAttributeName);
      transformationValues=BufferUtils.createFloatBuffer(16);

initialisation of transformation Matrix & loading into FloatBuffer, this happens every frame
      float movement=(float)Math.sin(timeElapsed/1000.0 * (2.314)/5);
      float angle=(float)(timeElapsed/1000.0*45)%360;
      Vector3f zAxis=new Vector3f(0f, 0f, 1f);
      Matrix4f translationMatrix=new Matrix4f();
      translationMatrix.setIdentity();
      translationMatrix.translate(new Vector3f(movement, 0f, 0f));
      Matrix4f rotationMatrix=new Matrix4f();
      rotationMatrix.setIdentity();
      rotationMatrix.rotate(angle, zAxis);
      Matrix4f transformationMatrix=Matrix4f.mul(translationMatrix, rotationMatrix, null);
      transformationValues.clear();
      transformationMatrix.store(transformationValues);

glUniformMatrix4() call, in every draw:
      [...]//other uniform attributes called here, such as fade
      glUniformMatrix4(transformMatrixAttributeIndex, false, transformationValues);

vertex shader code:
      #version 120
      attribute vec3 coord3D;
      attribute vec3 vColor;
      varying vec3 fColor;
      uniform float fade;
      uniform mat4 transformMatrix;
      void main(void) {
         gl_Position = transformMatrix * vec4(coord3D, 1.0);
         fColor = vColor;
      }

drawing itself is done by passing vertices and their colours through glVertexAttributePointer() calls, and then drawn through glDrawElements()

Again, the code itself works pretty fine without the transformation matrices, which leads me to think that is where the true problem lies. You can always take a complete look at the github repo mentioned above

Thanks a lot for any help guys. I know this may be tiresome to look at and try to trace the code like this, but I really am at a loss, and could really use a hand
Offline theagentd
« Reply #1 - Posted 2011-10-12 12:11:23 »

You forgot to flip the matrix float buffer? xD
EDIT: Yeah, the example is missing that too. xDDDDDDDD

Myomyomyo.
Offline codemonkey

Senior Newbie





« Reply #2 - Posted 2011-10-12 18:21:41 »

You forgot to flip the matrix float buffer? xD
EDIT: Yeah, the example is missing that too. xDDDDDDDD

You, Sir/Madam, ARE AWESOME! Thank you VERY much...
I guess that'll stick in my head this time Cheesy
Games published by our own members! Check 'em out!
Try the Free Demo of Droid Assault
Offline theagentd
« Reply #3 - Posted 2011-10-12 18:51:07 »

You forgot to flip the matrix float buffer? xD
EDIT: Yeah, the example is missing that too. xDDDDDDDD

You, Sir/Madam, ARE AWESOME! Thank you VERY much...
I guess that'll stick in my head this time Cheesy
Thank you. That would be Sir. xD Glad to help!

Myomyomyo.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (94 views)
2013-05-17 21:29:12

alaslipknot (102 views)
2013-05-16 21:24:48

gouessej (132 views)
2013-05-16 00:53:38

gouessej (127 views)
2013-05-16 00:17:58

theagentd (138 views)
2013-05-15 15:01:13

theagentd (126 views)
2013-05-15 15:00:54

StreetDoggy (168 views)
2013-05-14 15:56:26

kutucuk (189 views)
2013-05-12 17:10:36

kutucuk (192 views)
2013-05-12 15:36:09

UnluckyDevil (199 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.107 seconds with 21 queries.