Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Discussions / General Discussions / Re: Getting to other Platforms (iOS/HTML5 etc) - TouchAPi on: 2011-11-17 14:49:15
You just pointed me here from twitter, and i've already been following you for some time...

as i said, great work and please keep us updated on anything relating to the awesome #touchAPI and if you ever need a volunteer to work on this with you, i'm 100% ready
2  Game Development / Newbie & Debugging Questions / Re: Help me understand 3D, OpenGL, GLSL, LWJGL and life in general on: 2011-11-01 19:13:56
Thanks for the awesome replies everyone I will look into them and get back to you

if you're making a tutorial, that is

no, i'm not, but the best way I can understand something, is if i try to explain to someone else, and this is what i was trying to do here Smiley
3  Game Development / Newbie & Debugging Questions / Re: Help me understand 3D, OpenGL, GLSL, LWJGL and life in general on: 2011-11-01 17:03:56
3. Now that we have the cube drawing correctly, lets push it back a little bit to make sure we can see something else in the screen. Let's push it back to the camera target point for example

  • Ok, the camera points at 0,0,-4 in the world, so we need to push back our cube by 4 in the z direction; meaning we need to translate it by a vector of (0,0,-4). We will pass in this translation matrix to the shader, and let the GPU do the math. Hence, our shader becomes:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
#version 120
 
attribute vec3 coords;
attribute vec3 color;
uniform vec3 modelPosition;
varying vec3 fragmentColor;
 
void main(void) {
    mat4x4 positionMatrix=mat4x4(1.0);
    positionMatrix[3].x=modelPosition.x;
    positionMatrix[3].y=modelPosition.y;
    positionMatrix[3].z=modelPosition.z;

    gl_Position=gl_ModelViewProjectionMatrix*positionMatrix*vec4(coords,1.0);
    fragmentColor=color;
}
  • the Fragment shader does not change much, except for adding in the uniform declaration for the model position, to follow GLSL specs

Now HERE is where I'm stuck JGO. When I do this step, I get NOTHING drawn on the screen. What am I doing wrong? what am I missing?

Again, if you have read through ALL this, then thank you a MILLION and sorry for any waste of your time
4  Game Development / Newbie & Debugging Questions / Re: Help me understand 3D, OpenGL, GLSL, LWJGL and life in general on: 2011-11-01 16:55:56
2. Once this is set up, it is time to place your models in the world. For sake of brevity, I will create a very simple model of a cube, that is coloured. To do this, we load up a VBO with the vertex data, another with colour data per vertex, and an indices buffer (one that tells OpenGL how to go through the vertices drawing the different faces).

  • A cube has 8 vertices, each interleaved with is own colour, and i'll place them around the origin at first
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
float[] vertexAttributesData=new float[] {
   // front
   -1f, -1f, 1f, 1f, 0f, 0f,
   1f, -1f, 1f, 0f, 1f, 0f,
   1f, 1f, 1f, 0f, 0f, 1f,
   -1f, 1f, 1f, 1f, 1f, 1f,
   // back
   -1f, -1f, -1f, 1f, 0f, 0f,
   1f, -1f, -1f, 0f, 1f, 0f,
   1f, 1f, -1f, 0f, 0f, 1f,
   -1f, 1f, -1f, 1f, 1f, 1f,};


  • A cube has 6 faces, each created from 2 triangles, each again, created from 3 vertices. So, the indices matrix comes out like the following
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
int[] indecesData=new int[] {
   // front
   0, 1, 2, 2, 3, 0,
   // top
   1, 5, 6, 6, 2, 1,
   // back
   7, 6, 5, 5, 4, 7,
   // bottom
   4, 0, 3, 3, 7, 4,
   // left
   4, 5, 1, 1, 0, 4,
   // right
   3, 2, 6, 6, 7, 3};


  • Next up, we setup the Vertex Shader & the Fragment Shader to transform the cube vertices and colour to the screen
    • The Vertex Shader: does no real transformation at this point, and so just produces the output by applying the ModelViewProjection Matrix to the coordinates and hence, turns out as follows:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
#version 120

attribute vec3 coords;
attribute vec3 color;
varying vec3 fragmentColor;

void main(void) {
   gl_Position=gl_ModelViewProjectionMatrix*vec4(coords,1.0);
   fragmentColor=color;
}


  • The Fragment Shader: Also here does not do much, and hence just outputs the colours as specified in the model matrix, which makes it turn out to be simply
1  
2  
3  
4  
5  
6  
7  
#version 120

varying vec3 fragmentColor;

void main(void) {
   gl_FragColor=vec4(fragmentColor.x,fragmentColor.y,fragmentColor.z,1.0);
}
      [/li]

      [li]Finally, the Drawing process of the cube is a simple passing in of arguments to the shaders and drawing according to the indices[/li][/list]
      1  
      2  
      3  
      4  
      5  
      6  
      7  
      8  
      9  
      10  
      11  
      12  
      13  
      14  
      15  
      16  
      17  
      18  
      19  
      20  
      21  
      22  
      public void draw() {
         // bind vertex data array
         glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertexAttributesBuffer);

         // pass in info to vertex shader
         int dataOffset=0;
         glEnableVertexAttribArray(coordsAttributeIndex);
         glVertexAttribPointer(coordsAttributeIndex, numAxisPerVertex, GL_FLOAT, false, stride, 0);
         dataOffset+=numAxisPerVertex*bytesPerFloat;
         glEnableVertexAttribArray(colorAttributeIndex);
         glVertexAttribPointer(colorAttributeIndex, numColoursPerVertex, GL_FLOAT, false, stride, dataOffset);
         dataOffset+=numColoursPerVertex*bytesPerFloat;

         // draw the vertices using the indices
         glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, vertexIndicesBuffer);
         glDrawElements(GL_TRIANGLES, numIndeces, GL_UNSIGNED_INT, 0);

         // unbind the buffers & attribute arrays
         glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
         glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
         glDisableVertexAttribArray(colorAttributeIndex);
      }


        • FINALLY we can actually run and GET something drawn on the screen. What we get is the front face of the cube filling up the entire screen, because we placed the square vertices from -1 to 1, which fills up our entire area
        [/list]
        5  Game Development / Newbie & Debugging Questions / Re: Help me understand 3D, OpenGL, GLSL, LWJGL and life in general on: 2011-11-01 16:34:37
        1. Graphics programming is a little like photography, so you have to setup the scene, adjust the camera and then adjust the lens, so everything translates well into the picture. And then you just do this every frame. Those three stages roughly translate to the Model-View-Projection matrix and the way this works is as follows:

        • Setting up the world: This is where GLUT/LWJGL, etc come in, where you create an application window, and get a reference to the display window
        • Setting up the Scene[ie: The Model Matrix]: Here you setup the world. this happens usually as follows
        1  
        2  
        3  
        4  
        5  
        6  
        7  
        8  
        9  
        10  
        11  
        12  
        //switch to modelview matrix
        glMatrixMode(GL_MODELVIEW_MATRIX);
        //clear all that came before by setting matrix to 1
        glLoadIdentity();
        glShadeModel(GL_SMOOTH);
        glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // white
        glClearDepth(1.0f);
        glEnable(GL_DEPTH_TEST);
        GL11.glDepthFunc(GL11.GL_LESS);
        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);


        • Setting up the Camera[ie: The View Matrix]: While still in the modelview matrix mode, we move the camera to where it sits in the world, where it should point and the UP vector, that determines the gravity of the world. This is done by the gluLookAt() helper function
        1  
        gluLookAt(0f, 2f, 0f, 0f, 0f, -4f, 0f, 1f, 0f);


        • Setting up the Lens[ie: The Projection Matrix]: We switch the mode now to projection matrix, then set the field of view (the view angle), aspect ratio of the pic, near & far clipping planes. This is done by gluPerspective() helper function. Anything with a Z axis values LESS than (cameraZ+zNEAR) or GREATER than (cameraZ+zFAR) will not be shown on screen; anything else will be.

          In our specific case, this means for objects to be shown, they'll have to lie between the zPlanes of (-0.1 & -10)

          Again, the code for this is simply:
        1  
        2  
        3  
        glMatrixMode(GL11.GL_PROJECTION_MATRIX);
        glLoadIdentity();
        gluPerspective(45.0f, (float)width/(float)height, 0.1f, 10f);
          6  Game Development / Newbie & Debugging Questions / Help me understand 3D, OpenGL, GLSL, LWJGL and life in general on: 2011-11-01 16:34:01
          Hey All,

          I have been trying to port the Modern OpenGL Wikibook to LWJGL for a while now, and while I currently have a vague understanding of what is going on, I get stuck at times and then I realize, I don't really understand as much as I would like about the whole process, that makes me feel really dumb. So, instead of just asking another debugging question, I have decided to lay down my understanding of the complete process in this VERY long tread, to make sure that ACTUALLY I understand everything I think I do (apologies beforehand for the length of the post and THANKS a MILLION times if you read it all through).

          Please bear in mind that I write all of this, while keeping in mind that it has to be done through the shaders (the new/openglES way) and not classic glBegin()-glEnd() pair

          So, without further ado, here I go

          EDIT: You can check out the entire code over at the github repo for a more reader-friendly version
          7  Game Development / Newbie & Debugging Questions / nVidia Optimus Problem on: 2011-10-17 23:57:05
          Hey All,

          In the course of porting the OpenGL Wikibook to LWJGL (which I've posted about before) I have come across quite a curious case and was wondering if anyone can provide any input on the subject.

          I have a Dell XPS 502 laptop with nVidia Optimus on board. Now my problem is this: when I run any of the code (you can take a look at the github repo) everything runs well and dandy. However, if I switch the option on the nVidia control panel to ALWAYS use the nVidia chip instead of auto selecting, I get a blank screen, without anything drawn. The screen is cleared to the correct colour though, which makes me believe its something to do with the drawing code and not the initialisation?

          As I mentioned, you can checkout the code on the github repo, or for a quick look, you can check the question I posted here a few days ago, that has been solved, but without changing the code much (except of course for calling buffer.flip() which solved the problem)
          8  Game Development / Newbie & Debugging Questions / Re: Problem with Transformation Matrices passed into GLSL with LWJGL on: 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
          9  Game Development / Newbie & Debugging Questions / [SOLVED]Problem with Transformation Matrices passed into GLSL with LWJGL on: 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
          Pages: [1]
           

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

          The first screenshot will be displayed as a thumbnail.

          trollwarrior1 (31 views)
          2014-11-22 12:13:56

          xFryIx (72 views)
          2014-11-13 12:34:49

          digdugdiggy (51 views)
          2014-11-12 21:11:50

          digdugdiggy (45 views)
          2014-11-12 21:10:15

          digdugdiggy (39 views)
          2014-11-12 21:09:33

          kovacsa (63 views)
          2014-11-07 19:57:14

          TehJavaDev (68 views)
          2014-11-03 22:04:50

          BurntPizza (66 views)
          2014-11-03 18:54:52

          moogie (81 views)
          2014-11-03 06:22:04

          CopyableCougar4 (81 views)
          2014-11-01 23:36:41
          Understanding relations between setOrigin, setScale and setPosition in libGdx
          by mbabuskov
          2014-10-09 22:35:00

          Definite guide to supporting multiple device resolutions on Android (2014)
          by mbabuskov
          2014-10-02 22:36:02

          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
          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!