Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (113)
games submitted by our members
Games in WIP (562)
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 3667 times)
0 Members and 1 Guest are viewing this topic.
Offline codemonkey

Senior Newbie





« Posted 2011-10-12 02: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 10: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 16: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!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd
« Reply #3 - Posted 2011-10-12 16: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.

 

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

The first screenshot will be displayed as a thumbnail.

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

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

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

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

mitcheeb (49 views)
2014-09-08 06:06:29

BurntPizza (33 views)
2014-09-07 01:13:42

Longarmx (19 views)
2014-09-07 01:12:14

Longarmx (21 views)
2014-09-07 01:11:22

Longarmx (20 views)
2014-09-07 01:10:19

mitcheeb (30 views)
2014-09-04 23:08:59
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!