Java-Gaming.org Hi !
Featured games (88)
games approved by the League of Dukes
Games in Showcase (679)
Games in Android Showcase (194)
games submitted by our members
Games in WIP (734)
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  Game Development / Newbie & Debugging Questions / Re: [LWJGL] Attributes and VBO on: 2016-03-10 16:49:58
I tried with:
1  
Display.create(new PixelFormat(), new ContextAttribs(3, 3).withForwardCompatible(false).withProfileCore(true));

I got 3.3.11672 Core Profile Context.
It renders correctly without any attribute at location 0, thanks !

Just one minor difference;
1  
GL11.glPolygonMode(GL11.GL_BACK, GL11.GL_LINE);

does not work anymore (the faces are now filled on both sides, but in the compatible profile context with this call only the front was filled and lines for the back side...).
I guess it also is a deprecated function ? Do you know what should replace it ?
2  Game Development / Newbie & Debugging Questions / Re: [LWJGL] Attributes and VBO on: 2016-03-10 13:22:23
with the last driver I get 3.3.11672 Compatibility Profile Context
3  Game Development / Newbie & Debugging Questions / Re: [LWJGL] Attributes and VBO on: 2016-03-10 10:32:07
Thanks, I translated your example for lwjgl and learned a lot. How to use VAOs and elements indexes buffers for example.

I still have to test some things to get all the details I need. Ideally I would like to be compatible with most openGL versions (even found a friend with an older computer, not a gaming one obviously, but it does not support anything past openGL 2.1 !!!).

I still don't know what advantages I get from recent openGL, as I did not use those functions yet. For skeletal animation, it seems I won't be able to write a version for openGL 1.0 or 1.1, as it requires 2.0 functions. Finally, I feel I should write different shaders and associated java code for different openGL contexts.

I managed to remove all usage of glEnableClientState from my code, but to do that I needed to use instead:
1  
2  
GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, VSIZE, VOF);
GL20.glEnableVertexAttribArray(0);

The reason is that on this computer's openGL context, linking a vertex shader with an attribute at index 0 is not allowed. So I had to specifically make those calls for index 0 to get the model rendered!
4  Game Development / Newbie & Debugging Questions / Re: [LWJGL] Attributes and VBO on: 2016-03-07 15:34:21
Some progress on the no rendering bug I was mentioning with the full attributes vertex shader!

I updated this machine's graphics drivers, and now I get OpenGL version: 3.3.11672 Compatibility Profile Context.
For some reason, I had to reduce the declared uniforms by a lot for the shader to compile with this new version ! (The Bones mat4 table)
Also with this version I can use the "layout(location = X)" for my attributes (or still use the GL20.glBindAttribLocation method).

BUT!

I found this explanation. So it seems that my problem is that without asking for specific attributes locations I get those values:
1  
2  
3  
4  
5  
Vertex id = 4
Normal id = 3
Color  id = 1
Index  id = 2
Weight id = 5

And if I force any location value (in the shader or with GL20.glBindAttribLocation), the shader will fail to link for the location 0 (other values are allowed).
But the reserved location 0 is the one for gl_Vertex or something, and rendering functions won't do anything without it. That is what I got from the previous link;
Quote
This is because, in GL versions before 3.1, all array rendering functions were defined in terms of calls to glArrayElement, which used immediate mode-based rendering. That means that you need something to provoke the vertex. Recall that, in immediate mode, calling glVertex*() not only sets the vertex position, it also causes the vertex to be sent with the other attributes. Calling glVertexAttrib*(0, ...) does the same thing. That's why older versions require you to use either attribute 0 or GL_VERTEX_ARRAY.

So now I have to find a way to either use this location 0 even if not allowed or another way to render on this old computer...
5  Game Development / Newbie & Debugging Questions / Re: [LWJGL] Attributes and VBO on: 2016-03-04 16:25:09
OpenGL 3.2 is fine for being the oldest, operating system and gpu?

About the Hello World, what you saw in the window was right, it just clears the color to red Smiley

We can focus on 3.2 at the moment, no big deal, in this case I have another sample where you can take inspiration.
windows 7 and ATI Radeon HD 4250 Graphics
gonna check that sample, thanks !
6  Game Development / Newbie & Debugging Questions / Re: [LWJGL] Attributes and VBO on: 2016-03-04 16:07:22
I will use GitHub as suggested, in the meantime here is my complete main class:
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  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
237  
238  
239  
240  
241  
242  
243  
244  
245  
246  
247  
248  
249  
package lwjgl;
import java.nio.FloatBuffer;
import java.util.LinkedList;

import org.lwjgl.BufferUtils;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL15;
import org.lwjgl.opengl.GL20;
import org.lwjgl.util.vector.Matrix4f;
import org.lwjgl.util.vector.Vector3f;



public class AnimTest
{ public static void main(String[] args)
  { System.out.println("CPU : "+Runtime.getRuntime().availableProcessors());
    new AnimTest().start();
  }

  private static final Vector3f AXIS = new Vector3f(0, 0, 1), BIGGER = new Vector3f(1f, 1.01f, 1.01f), TINIER = new Vector3f(1f, 1f/1.01f, 1f/1.01f);
  private static final int VOF = 0, NOF = VOF+3*4, COF = NOF+3*4, IOF = COF+3*4, WOF = IOF+2*4, VSIZE = WOF+2*4;
  private static int VERTEX, NORMAL, COLOR, INDEX, WEIGHT;

  private boolean up = false, down = false, left = false, right = false;
  private Vector3f[] pos = {new Vector3f(-4, 0, 0), new Vector3f(0, 0, 0), new Vector3f(4, 0, 0)};
  private Matrix4f[] rot = {new Matrix4f(), new Matrix4f(), new Matrix4f()};
  private Matrix4f[] sca = {new Matrix4f(), new Matrix4f(), new Matrix4f()};
  private Matrix4f[] bones = {new Matrix4f(), new Matrix4f(), new Matrix4f()};

  private void bone(int i)
  { bones[i].setIdentity();
    if (i != 1) Matrix4f.mul(bones[i], rot[1], bones[i]);
    bones[i].translate(pos[i]);
    Matrix4f.mul(bones[i], rot[i], bones[i]);
    bones[i].translate(pos[2-i]);
    Matrix4f.mul(bones[i], sca[i], bones[i]);
  }

  private void rotate(int i, float angle) {rot[i].rotate(angle, AXIS); bone(i); if (i == 1) {bone(0); bone(2);}}

  private void bigger(int i) {sca[i].scale(BIGGER); bone(i);}

  private void tinier(int i) {sca[i].scale(TINIER); bone(i);}

  public AnimTest() {}

  public void start()
  { try
    { Display.setFullscreen(true);
      Display.setVSyncEnabled(true);
      Display.create();
      final int W = Display.getWidth(), H = Display.getHeight();

      System.out.println("OpenGL version: " + GL11.glGetString(GL11.GL_VERSION));

      // Create the camera
      Camera camera = new Camera();
      camera.updatePerspectiveProjection((float)Math.PI/4, (float)W / (float)H, 0.1f, 100f);

      // Create Shader Program
      ShaderProgram shaderProgram = new ShaderProgram("VertexShader2.src", "FragmentShader.src");
      Vector3f light = new Vector3f();

      // Enable face culling
      GL11.glPolygonMode(GL11.GL_BACK, GL11.GL_LINE);
   
      // Enable Client states
      GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
      GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);
      GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);

      // Use shader
      shaderProgram.bind();
      shaderProgram.setUniform("ambientCoefficient", 0.5f);
      shaderProgram.setUniform("textured", 0);
      shaderProgram.setUniform("boned", 1);

      GL11.glClearColor(0, 0, 0, 1);
      //GL11.glColor3f(0.5f, 0, 1);

      // Enable depth testing
      GL11.glEnable(GL11.GL_DEPTH_TEST);

      boolean running = true, normals = false, colors = false;
      int size = 0, resolution = 64, frames = 0, mouseWheel;
      long time = System.currentTimeMillis(), log = time+1000;
      LinkedList<Triangle3D> faces = null;
      FloatBuffer vbuf = null;
      float pow = 1;

      int vboVertexID = GL15.glGenBuffers();

      VERTEX = shaderProgram.getAttributeLocation("Vertex");
      NORMAL = shaderProgram.getAttributeLocation("Normal");
      COLOR  = shaderProgram.getAttributeLocation("Color");
      INDEX  = shaderProgram.getAttributeLocation("Index");
      WEIGHT = shaderProgram.getAttributeLocation("Weight");

      System.out.println("Vertex id = "+VERTEX);
      System.out.println("Normal id = "+NORMAL);
      System.out.println("Color  id = "+COLOR);
      System.out.println("Index  id = "+INDEX);
      System.out.println("Weight id = "+WEIGHT);

      // Bind the vertex buffer
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboVertexID);
      GL11.glVertexPointer(3, GL11.GL_FLOAT, VSIZE, VOF);
      GL11.glNormalPointer(GL11.GL_FLOAT, VSIZE, NOF);
      GL11.glColorPointer(3, GL11.GL_FLOAT, VSIZE, COF);
      GL20.glVertexAttribPointer(VERTEX, 3, GL11.GL_FLOAT, false, VSIZE, VOF);
      GL20.glVertexAttribPointer(NORMAL, 3, GL11.GL_FLOAT, false, VSIZE, NOF);
      GL20.glVertexAttribPointer(COLOR,  3, GL11.GL_FLOAT, false, VSIZE, COF);
      GL20.glVertexAttribPointer(INDEX,  2, GL11.GL_FLOAT, false, VSIZE, IOF);
      GL20.glVertexAttribPointer(WEIGHT, 2, GL11.GL_FLOAT, false, VSIZE, WOF);
      GL20.glEnableVertexAttribArray(VERTEX);
      GL20.glEnableVertexAttribArray(NORMAL);
      GL20.glEnableVertexAttribArray(COLOR);
      GL20.glEnableVertexAttribArray(INDEX);
      GL20.glEnableVertexAttribArray(WEIGHT);

      while (running && !Display.isCloseRequested())
      { long t = System.currentTimeMillis(); //float deltaTime = (t-time)/1000f;
        if ((time = t) >= log)
        { System.out.println("Resolution = "+resolution+", "+frames+" frames per second");
          frames = 0; log += 1000;
        }
        while (Keyboard.next()) if (Keyboard.getEventKeyState()) switch (Keyboard.getEventKey())
         { case Keyboard.KEY_ESCAPE : running = false; break;
           case Keyboard.KEY_ADD : resolution++; faces = null; break;
           case Keyboard.KEY_SUBTRACT : if (resolution > 0) {resolution--; faces = null;} break;
           case Keyboard.KEY_W : pow *= 1.1f; faces = null; break;
           case Keyboard.KEY_X : pow /= 1.1f; faces = null; break;
           case Keyboard.KEY_C : colors = !colors; faces = null; break;
           case Keyboard.KEY_N : normals = !normals; break;
         }

        if (Keyboard.isKeyDown(Keyboard.KEY_1)) rotate(0, -(float)(Math.PI/180));
        if (Keyboard.isKeyDown(Keyboard.KEY_2)) rotate(0, +(float)(Math.PI/180));
        if (Keyboard.isKeyDown(Keyboard.KEY_3)) rotate(1, -(float)(Math.PI/180));
        if (Keyboard.isKeyDown(Keyboard.KEY_4)) rotate(1, +(float)(Math.PI/180));
        if (Keyboard.isKeyDown(Keyboard.KEY_5)) rotate(2, -(float)(Math.PI/180));
        if (Keyboard.isKeyDown(Keyboard.KEY_6)) rotate(2, +(float)(Math.PI/180));

        if (Keyboard.isKeyDown(Keyboard.KEY_A)) tinier(0);
        if (Keyboard.isKeyDown(Keyboard.KEY_Z)) bigger(0);
        if (Keyboard.isKeyDown(Keyboard.KEY_E)) tinier(1);
        if (Keyboard.isKeyDown(Keyboard.KEY_R)) bigger(1);
        if (Keyboard.isKeyDown(Keyboard.KEY_T)) tinier(2);
        if (Keyboard.isKeyDown(Keyboard.KEY_Y)) bigger(2);

        left = Keyboard.isKeyDown(Keyboard.KEY_LEFT);
        up = Keyboard.isKeyDown(Keyboard.KEY_UP);
        right = Keyboard.isKeyDown(Keyboard.KEY_RIGHT);
        down = Keyboard.isKeyDown(Keyboard.KEY_DOWN);
       
        if (Mouse.isButtonDown(0)) camera.navigate(Mouse.getDX(), Mouse.getDY());
        if (Mouse.isButtonDown(1)) camera.navigate(Mouse.getDX(), Mouse.getDY());
        if (Mouse.isButtonDown(2)) camera.navigate(Mouse.getDX(), Mouse.getDY());
        if (left) camera.navigate(4, 0);
        if (right) camera.navigate(-4, 0);
        if (up) camera.navigate(0, -4);
        if (down) camera.navigate(0, 4);
       
        mouseWheel = Mouse.getDWheel();

        if (mouseWheel < 0) camera.move(1); else if (mouseWheel > 0) camera.move(-1);

        // Clear the screen and depth buffer
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

        double a1 = (time%7000)*2*Math.PI/7000, a2 = (time%11000)*2*Math.PI/11000, d = 1*(Math.cos((time%13000)*2*Math.PI/13000)+3),
               cos1 = Math.cos(a1), sin1 = Math.sin(a1), cos2 = Math.cos(a2), sin2 = Math.sin(a2);
        light.set((float)(d*cos1*cos2), (float)(d*sin2), (float)(d*sin1*cos2));
        shaderProgram.setUniform("lightPos", light);
        shaderProgram.setUniform("mProjection", camera.getProjectionMatrix());
       
        camera.apply(shaderProgram);

        shaderProgram.setUniform("Bones", bones);

        if (faces == null)
        { faces = faces(resolution, pow);
          size = 3*faces.size();
          int bufferSize = size*VSIZE;
          if (vbuf == null || vbuf.capacity() < bufferSize) vbuf = BufferUtils.createFloatBuffer(bufferSize);
          if (colors) for (Triangle3D f : faces) f.loadrgb(vbuf); else for (Triangle3D f : faces) f.load(vbuf);
          System.out.println(size+" points loaded in buffer.");
          vbuf.flip();
          GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vbuf, GL15.GL_DYNAMIC_DRAW);
        }
        GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, size);

        if (normals)
        { GL11.glBegin(GL11.GL_LINES);
          GL11.glColor3f (1, 1, 1);
          for (Triangle3D f : faces) f.undrawNormals();
          for (Triangle3D f : faces) f.drawAnimationNormals(VERTEX, NORMAL, COLOR, INDEX, WEIGHT);
          GL11.glEnd();
        }

        Display.update();
        frames++;
      }
      Display.destroy();
    }
    catch (Exception e) {e.printStackTrace(); System.exit(0);}
  }

  private LinkedList<Triangle3D> faces(int resolution, float power)
  { LinkedList<Triangle3D> result = new LinkedList<Triangle3D>();
    Point3D[] circle = new Point3D[3+3*resolution];
    for (int j = 0; j < circle.length; j++)
    { double a = 2*Math.PI*j/circle.length;
      float cos = (float)Math.cos(a), sin = (float)Math.sin(a);
      circle[j] = new Point3D(null, -8, cos, sin, 0, cos, sin, 1, 0, 0);
    }
    for (int i = 0; i<=resolution; i++)
    { Point3D[] old = circle;
      circle = new Point3D[3+3*resolution];
      float f = (float)(i+1)/(float)(resolution+1);
      float x = -8+16*f;
      float a, b, c;
      if (f < 0.5f)
      { a = f < 0.25f ? 0.5f + 0.5f*(float)Math.pow(1-4*f, power) : 0.5f - 0.5f*(float)Math.pow(4*f-1, power);
        b = 1-a;
        c = 0;
      }
      else
      { a = 0;
        b = f < 0.75f ? 0.5f + 0.5f*(float)Math.pow(3-4*f, power) : 0.5f - 0.5f*(float)Math.pow(4*f-3, power);
        c = 1-b;
      }
      for (int j = 0; j < circle.length; j++)
      { double angle = 2*Math.PI*(j+0.5*(1-i%2))/circle.length;
        float cos = (float)Math.cos(angle), sin = (float)Math.sin(angle);
        circle[j] = new Point3D(null, x, cos, sin, 0, cos, sin, a, b, c);
      }
      for (int j = 0; j < circle.length; j++)
      { int k = (j+1)%circle.length, l = i%2==0 ? j : k, m = (l+1)%circle.length;
        result.add(new Triangle3D(old[j], old[k], circle[l], null));
        result.add(new Triangle3D(circle[m], circle[l], old[k], null));
      }
    }
    return result;
  }
}


So, if I comment this part:
1  
2  
3  
      GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
      GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);
      GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);

and this part:
1  
2  
3  
      GL11.glVertexPointer(3, GL11.GL_FLOAT, VSIZE, VOF);
      GL11.glNormalPointer(GL11.GL_FLOAT, VSIZE, NOF);
      GL11.glColorPointer(3, GL11.GL_FLOAT, VSIZE, COF);

then nothing renders anymore !

The Vertex shader:
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  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
// The Vertex Color
varying vec4 vColor;
// The Vertex Position
varying vec3 vPosition;
// The Vertex Normal
varying vec3 vNormal;
// The Vertex Texture Coordinates
varying vec2 vTexture;

// The vertex position
attribute vec3 Vertex;
// The normal
attribute vec3 Normal;
// The color
attribute vec3 Color;
// The bones index attributes
attribute vec2 Index;
// The bones weight for each indexed bone
attribute vec2 Weight;

// The view matrix
uniform mat4 mView;
// The projection matrix
uniform mat4 mProjectionView;

// The texture mode
uniform float textured;

// the bone mode
uniform float boned;
// The bones
uniform mat4 Bones[1000];

void main()
{ if (boned == 1.0)
  { // weighted animation
    vec4 v = vec4(Vertex, 1.0);
    vec4 n = vec4(Normal, 0.0);
    v = vec4((Bones[int(Index.x)] * v * Weight.x + Bones[int(Index.y)] * v * Weight.y).xyz, 1.0);
    n = vec4((Bones[int(Index.x)] * n * Weight.x + Bones[int(Index.y)] * n * Weight.y).xyz, 0.0);

    // Pass the color to the fragment shader
    vColor = vec4(Color, 1.0);
   
    // Pass the vertex to the fragment shader
    vPosition = (mView * v).xyz;
   
    // Pass the normal to the fragment shader
    vNormal = normalize(mView * n).xyz;
   
    // Pass the texture coordinates to the fragment shader
    vTexture = gl_MultiTexCoord0.xy;

    // Calculate the transformed vertex
    gl_Position = mProjectionView * v;
  }
  else
  { // Pass the color to the fragment shader
    vColor = gl_Color;
   
    // Pass the vertex to the fragment shader
    vPosition = (mView * gl_Vertex).xyz;
   
    // Pass the normal to the fragment shader
    vNormal = normalize(mView * vec4(gl_Normal.xyz, 0.0)).xyz;
   
    // Pass the texture coordinates to the fragment shader
    vTexture = gl_MultiTexCoord0.xy;

    // Calculate the transformed vertex
    gl_Position = mProjectionView * gl_Vertex;
  }
}
7  Game Development / Newbie & Debugging Questions / Re: [LWJGL] Attributes and VBO on: 2016-03-04 14:48:33
I did it, I used GL20.glEnableVertexAttribArray(VERTEX); but it was before the binding of the VBO. So I tried to put the lines in the same order you suggested, but still nothing renders at all...
8  Game Development / Newbie & Debugging Questions / Re: [LWJGL] Attributes and VBO on: 2016-03-04 14:07:03
Thanks you for the code !

I just checked the supported version of openGL on this computer (I work on several computers of very different capacities and ages, this one is among the oldest!) with
1  
System.out.println("OpenGL version: " + GL11.glGetString(GL11.GL_VERSION));

the result:
3.2.9606 Compatibility Profile Context

Also, I ran the HelloWorld example in your second link with LWJGL 3.0.0b build 64, it does not seem to deal with triangles but displays a red-filled window Smiley
In your Hello Triangle source I see you use a GL4 object, I suppose it would correspond to the GL40 class in lwjgl. So on the computer I currently use I guess it will not work!

I am still trying to understand what is happening in my previous code...
One thing is clear now; when I use ONLY attributes, GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, size); renders absolutely nothing, and when I use at least one predefined shader entry like gl_Vertex, with the GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY); everything is rendered, custom attributes included.

Any idea why?
9  Game Development / Newbie & Debugging Questions / Re: [LWJGL] Attributes and VBO on: 2016-03-02 15:58:11
Ok, so, what is deprecated exactly, is it GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY); ?

Is it the usage of gl_Vertex, gl_Normal and gl_Color in vertex shader ?

What upgrade should I do ? I am just learning for the moment, I don't have a very big code to handle, so I really want to upgrade! If you have a link with code example that just does what I try to do (buffering meshes with skeleton animation support) or simply know what should replace the deprecated code, please tell me Smiley
10  Game Development / Newbie & Debugging Questions / Re: [LWJGL] Attributes and VBO on: 2016-03-02 14:54:38
Alright, thank you for those infos !

I totally agree that it is very hard to find good documents on the web about openGL and its different versions, tutorials or examples.

I finally managed to render the model as I wanted. But I had to remove the attributes I used for the vertex position, normal and color and use the default GLSL variables instead. So I have now only this in the vertex shader:
1  
2  
3  
4  
// The bones index attributes
attribute vec2 Index;
// The bones weight for each indexed bone
attribute vec2 Weight;


Before the rendering loop I use this (I commented the lines when I tried to use attributes for everything vertex related in the previous version):
1  
2  
3  
      GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
      GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);
      GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);


I get the 2 attributes indexes after binding the shaderProgram this way:
1  
2  
      INDEX  = shaderProgram.getAttributeLocation("Index");
      WEIGHT = shaderProgram.getAttributeLocation("Weight");

and enable the attributes this way:
1  
2  
      GL20.glEnableVertexAttribArray(INDEX);
      GL20.glEnableVertexAttribArray(WEIGHT);


So I render the model with this in the loop:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
        // Bind the vertex buffer
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboVertexID);
        if (faces == null)
        { faces = faces(resolution);
          size = 3*faces.size();
          int bufferSize = size*VSIZE;
          if (vbuf == null || vbuf.capacity() < bufferSize) vbuf = BufferUtils.createFloatBuffer(bufferSize);
          if (colors) for (Triangle3D f : faces) f.loadrgb(vbuf); else for (Triangle3D f : faces) f.load(vbuf);
          System.out.println(size+" points loaded in buffers.");
          vbuf.flip();
          GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vbuf, GL15.GL_DYNAMIC_DRAW);
        }
        GL11.glVertexPointer(3, GL11.GL_FLOAT, VSIZE, VOF);
        GL11.glNormalPointer(GL11.GL_FLOAT, VSIZE, NOF);
        GL11.glColorPointer(3, GL11.GL_FLOAT, VSIZE, COF);
        GL20.glVertexAttribPointer(INDEX,  2, GL11.GL_FLOAT, false, VSIZE, IOF);
        GL20.glVertexAttribPointer(WEIGHT, 2, GL11.GL_FLOAT, false, VSIZE, WOF);
        GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, size);

When I previously removed GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY); and used the attribute vec3 Vertex instead the model was not rendered at all! I still don't understand clearly why... If you have any advice on what I could do better in this code, tell me!

Also, what is Vulkan exactly? Smiley
Oh and I should may be start using LWJGL3, last time I checked it, it did not include any math utils classes for matrices and vectors, I was pissed and thought I should check it later when it would be less brutal!
11  Game Development / Newbie & Debugging Questions / Re: [LWJGL] Attributes and VBO on: 2016-03-01 17:07:11
I did not use anything post version 2.0 for now.
12  Game Development / Newbie & Debugging Questions / [LWJGL] Attributes and VBO on: 2016-03-01 16:36:22
Hello !

I am confused about the way I should transfer attributes values to a Vertex Shader using buffers. In the shader I defined this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
// The vertex position
attribute vec3 Vertex;
// The normal
attribute vec3 Normal;
// The color
attribute vec3 Color;
// The bones index attributes
attribute vec2 Index;
// The bones weight for each indexed bone
attribute vec2 Weight;


in java I use this code to render (the 3D model may dynamically update):

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboVertexID);
        if (faces == null)
        { faces = faces(resolution);
          size = 3*faces.size();
          int bufferSize = size*VSIZE;
          if (vbuf == null || vbuf.capacity() < bufferSize) vbuf = BufferUtils.createFloatBuffer(bufferSize);
          if (colors) for (Triangle3D f : faces) f.loadrgb(vbuf); else for (Triangle3D f : faces) f.load(vbuf);
          System.out.println(size+" points loaded in buffers.");
          vbuf.flip();
          GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vbuf, GL15.GL_DYNAMIC_DRAW);
        }
        //GL11.glVertexPointer(3, GL11.GL_FLOAT, VSIZE, VOF);
        //GL11.glNormalPointer(GL11.GL_FLOAT, VSIZE, NOF);
        //GL11.glColorPointer(3, GL11.GL_FLOAT, VSIZE, COF);
        GL20.glVertexAttribPointer(VERTEX, 3, GL11.GL_FLOAT, false, VSIZE, VOF);
        GL20.glVertexAttribPointer(NORMAL, 3, GL11.GL_FLOAT, false, VSIZE, NOF);
        GL20.glVertexAttribPointer(COLOR,  3, GL11.GL_FLOAT, false, VSIZE, COF);
        GL20.glVertexAttribPointer(INDEX,  2, GL11.GL_FLOAT, false, VSIZE, IOF);
        GL20.glVertexAttribPointer(WEIGHT, 2, GL11.GL_FLOAT, false, VSIZE, WOF);
        GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, size);


As you can see I tried different methods (commented) and I read here and there that there is old and modern ways to do this, but I still don't know what is the modern and best solution ! All I get with this code for now is nothing rendered !

I know how to use vbo buffers correctly with the default openGL vertex shader variables, I also know how to use attributes without vbo, for example with GL20.glVertexAttrib2f(weight, a, b), but I don't understand how to do both !
13  Game Development / Newbie & Debugging Questions / Re: [LWJGL] problem with alpha texture and GL_LINEAR rendering on: 2014-05-07 15:32:21
Yeah ! Excellent, now I know all that I needed to rule the gaming world, thanks !!! mouhahahahaha Grin
14  Game Development / Newbie & Debugging Questions / Re: [LWJGL] problem with alpha texture and GL_LINEAR rendering on: 2014-05-07 15:07:24
Thanks a lot!

I just tested this solution and it's perfect to remove any artifact inside a bloc with abrupt alpha jumps !

However, I still have the problem with the blocs' borders.
It's obvious that when the texture of a bloc is scaled, its last line is interpolated with its first line, and its last column with its first one.
Is there anything I can do about this ?
15  Game Development / Newbie & Debugging Questions / [LWJGL] problem with alpha texture and GL_LINEAR rendering on: 2014-05-07 12:03:23
Hello!

I'm using lwjgl to render a 2D scene. The map is based on blocks referencing textures.

here is the init code for orthographic view and alpha channel;
1  
2  
3  
4  
5  
6  
7  
8  
      GL11.glMatrixMode(GL11.GL_PROJECTION);
      GL11.glLoadIdentity();
      GL11.glOrtho(0, W, H, 0, 1, -1);
      GL11.glMatrixMode(GL11.GL_MODELVIEW);      

      GL11.glEnable(GL11.GL_TEXTURE_2D);
      GL11.glEnable(GL11.GL_BLEND);
      GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);


the textures are loaded (then all mipmap levels are generated), they have the following parameters:
1  
2  
3  
4  
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, w, h, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);


I tried the alternatives to LINEAR and LINEAR_MIPMAP_LINEAR modes with NEAREST but so far I see rendering artifacts when the textures are scaled (zoom in or out).

Here are some examples of what I get with linear interpolation:



These are some basic textures with a strong zoom. As you can see there are artifacts on the border of the bloc, a dark semi-transparent line which comes from a pixel mix with the opposite side of the texture (dark lines can also be seen at the transition between opaque and transparent zones but are less problematic). I checked that the original textures do not include those artifacts.

So the default linear pixel mixing openGL function really does not seem appropriate to just draw scaled alpha textures Huh Isn't that weird ? Is there a solution to remove those unwanted lines ? Does it require some GLSL code or is there a standard method ? (Would the result be the same if I used a 3D projection matrix instead of an orthogonal one ?)

Thanks for reading Smiley
16  Game Development / Newbie & Debugging Questions / Re: Direct 2D pixels manipulation on: 2013-10-11 11:11:29
Sounds great ! Do you have any example / link available on this subject ? (Trust me I tried to find it but I'm completely lost right now)
17  Game Development / Newbie & Debugging Questions / Direct 2D pixels manipulation on: 2013-10-11 09:54:37
Hello, I recently started to search for high FPS 2D screen pixels manipulation, and realized I needed something faster than java2D. The big bottleneck is the permanent transfer between cpu memory and video card memory, especially for a full screen high resolution buffer. Until recently I worked on a 2D/3D creation software. It didn't need high FPS but needed high quality and totally pixel controlled results (for the 2D creation part). I see in many posts that direct pixel manipulation is kind of discouraged by experienced posters. Well for now I would like to manipulate pixels anyway, and later learn other ways to do fast rendering. But I didn't find a very clear example that does just that. I'm a little lost with the PBO / pbuffers /frame buffers usage. Here is a short class that just draws a random color on each pixel and shows FPS for java2D.

My question is what would be the equivalent code if I used LWJGL?

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  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
import java.awt.AWTException;
import java.awt.BufferCapabilities;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.ImageCapabilities;
import java.awt.BufferCapabilities.FlipContents;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.util.Random;

import javax.swing.JFrame;

public class Test
{ private final static GraphicsDevice screen = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
  private final static Random random = new Random(System.currentTimeMillis());

  public static void main(String[] args)
  { System.setProperty("sun.java2d.opengl", "true");
    final JFrame f = new JFrame("TEST");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setUndecorated(true);
    f.setResizable(false);
    f.setIgnoreRepaint(true);
    screen.setFullScreenWindow(f);
    f.addKeyListener(new KeyListener()
    { public void keyPressed(KeyEvent e) {System.exit(0);}
      public void keyReleased(KeyEvent e) {}
      public void keyTyped(KeyEvent e) {}
    });
    final int w = f.getWidth(), h = f.getHeight();
    try {f.createBufferStrategy(2, new BufferCapabilities(new ImageCapabilities(true), new ImageCapabilities(true), FlipContents.UNDEFINED));}
    catch (AWTException e) {e.printStackTrace();}
    final BufferStrategy s = f.getBufferStrategy();
    final BufferedImage img = screen.getDefaultConfiguration().createCompatibleImage(w, h);
    final int[] pixels = ((DataBufferInt)img.getRaster().getDataBuffer()).getData();
    long time = 0, frames = 0;
    final long start = System.currentTimeMillis();
    while (true) try
    { final Graphics g = s.getDrawGraphics();
      for (int k = w*h; k-->0;) pixels[k] = random.nextInt();
      g.drawImage(img, 0, 0, null);
      time = System.currentTimeMillis()-start;
      frames++;
      if (time>0)
      { String m = "FPS : "+(frames*1000.0/time); int sw = g.getFontMetrics().stringWidth(m);
        g.setColor(Color.BLACK); g.fillRect((w-sw)/2, h/2-20, sw, 30);
        g.setColor(Color.WHITE); g.drawString(m, (w-sw)/2, h/2);
      }
      s.show();
      g.dispose();
    }
    catch (Exception e)
    { e.printStackTrace();
      System.exit(0);
    }
  }
}
Pages: [1]
 
DarkCart (16 views)
2016-05-29 02:30:33

Hydroque (32 views)
2016-05-26 14:45:46

Mac70 (45 views)
2016-05-24 21:16:33

theagentd (48 views)
2016-05-14 18:38:35

theagentd (82 views)
2016-05-10 22:37:41

theagentd (89 views)
2016-05-10 22:33:46

IanParcs (115 views)
2016-04-18 14:18:53

KaiHH (114 views)
2016-04-18 08:35:41

KaiHH (135 views)
2016-04-15 12:43:58

theagentd (140 views)
2016-04-14 02:16:17
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

List of Learning Resources
by SilverTiger
2016-02-05 09:39:47

List of Learning Resources
by SilverTiger
2016-02-05 09:38:38

List of Learning Resources
by SilverTiger
2016-02-05 09:35:50
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!