Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (491)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
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  Java Game APIs & Engines / OpenGL Development / Re: Double VBO no performance increase or decrease? on: 2014-01-18 17:34:23

** Other part of quote **

Take a look at Riven's excellent implementation here on how to implement that: http://www.java-gaming.org/topics/opengl-lightning-fast-managed-vbo-mapping/28209/view.html

I see, I did not know this, either way I was going to work my way up to the glMapBufferRange. I guess I will just have to jump up to there. I'll have to take a look at that article again and try to implement it.

There are other aspects to consider as well.  200,000 calls to Math.random() may be the bottleneck in which case you won't see performance changes from the GPU.  Similarly, you might be fill-rate limited so you won't see performance changes until you reduce screen resolution, overdraw or simplify your fragment shader.

I don't know if this matters but since you mention this you could be right. I don't think it would effect it that much but I'm not sure.
I doing my tests on a 800 x 600 window. My Fragment Shader is as simple as possible I think, it just returns the color red. Could you explain overdraw I'm unfamiliar with this term in the openGL context.

Also was I confusing my terms for VBOs? Basically should I consider this my VBO
1  
2  
//VBO or just some storage space for Vertex Data
FloatBuffer vertexBuffer = BufferUtils.createFloatBuffer(MAX_VERTEX_COUNT);


or is my VBO really this
1  
2  
3  
4  
5  
//My VBO or just a pointer to the VBO and its data
IntBuffer buffers = BufferUtils.createIntBuffer(1);
glGenBuffers(buffers);
     
int vertexBufferHandle = buffers.get(0);

2  Java Game APIs & Engines / OpenGL Development / Re: Double VBO no performance increase or decrease? on: 2014-01-17 03:47:49
Double buffering, unless I'm mistaken, is for framebuffers, and it makes sure that the whole window is drawn before displaying it on screen.

LWJGL uses it by default.

Generally the bottleneck with OpenGL is the amount of glXXX commands you're using, so if you can cut more of them out, then you save time. (There are a few commands that are more expensive, but that's the general idea)

I think we are talking about 2 different things, I'm talking about the rendering technique where you use one VBO to write data to and then the GPU updates/uses the other VBO.

You might see an improvement with multiple buffers if doing many small batches.

Really? You think that would matter, I would figure that attempting to render 100000 quads every frame where the data changes would surely cause  a performance hit. I'll have to try it

Also I was wondering this, maybe I'm confusing the terms Vertex Buffer and Vertex Buffer Handle. When I use the glGenBuffers() command, this in my mind creates the Vertex Buffer Handle. Where the Vertex Buffer (as I think of it) is the FloatBuffer created. So maybe I'm really supposed to be swapping the Vertex Buffer Handles? Where then I would just have one FloatBuffer that us used for writing

Then when I bind the FloatBuffer and the Vertex Buffer Handle, this takes the data and 'dumps' it on the GPU. Where then the Vertex Buffer Handle is responsible for its association. And then I can just use the same FloatBuffer for my data

Or is that just completely off the wall?
3  Java Game APIs & Engines / OpenGL Development / Double VBO no performance increase or decrease? on: 2014-01-17 02:02:17
I have been attempting to get a double VBO system going. To my understanding it is nothing really special just create 2 VBOs and then fill them up right? So that is what I have done, but I have no performance gain or performance decrease according to my DT times.

It does not matter how many buffers I use (keeping one VBO or having 2 at the ready) my DT times are roughly the same.
Both with single and double VBOs it sits around .0024 seconds.

Surely, I would think that my DT time would be better with a double VBO assuming I did it right or worse if it was done wrong. But them being the same? It has to be wrong, right?

Here is the code I got, let me know if more info I needed. I am rendering 100000 32x32 quads
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  
   public void render()
   {
                //Clear the current buffer
     vertexBuffer[buffer].clear();

                //Set up a new random for the positions
     int x = 0; int y = 0;
      Random random = new Random();
     
      //X and Ys for the Quad; The Z is set to 1.0f; Remember 100000 quads
     for(int i = 0; i < MAX_QUADS; i++)
      {
         x = random.nextInt(800);
         y = random.nextInt(600);
         draw(x, y, 32.0f, 32.0f);
      }
     
      //Flip the current buffer
     vertexBuffer[buffer].flip();
     
      //Use the shader program
     glUseProgram(shaderProgramHandle);
     
                //Bind the current buffer and send it off to queue up in the GPU
     glBindBuffer(GL_ARRAY_BUFFER, vertexBufferHandle);
      glBufferData(GL_ARRAY_BUFFER, vertexBuffer[buffer], GL_STREAM_DRAW);
     
      //Get the Uniform for the MVP shader
     glUniformMatrix4(matrixBufferHandle, false, mvpBuffer);
     
      //Enable the VAO and its attributes
     glBindVertexArray(vertexArrayHandle);
      GL11.glDrawElements(GL_TRIANGLES, indexDrawCount, GL11.GL_UNSIGNED_INT, 0);
      glBindVertexArray(0);
     
      buffer = 1 - buffer;
   }

        //Put in here just in case
  private void createBuffers()
   {  
                //Create the Vertex Buffers
     vertexBuffer = new FloatBuffer[2];
      vertexBuffer[0] = BufferUtils.createFloatBuffer(MAX_VERTEX_COUNT);
      vertexBuffer[1] = BufferUtils.createFloatBuffer(MAX_VERTEX_COUNT);
   
                //Index Buffer used
     indexBuffer = BufferUtils.createIntBuffer(MAX_INDEX_COUNT);
   }


Other things to mention I'm using one VAO, one Vertex Buffer Handle, and a Index buffer handle like so
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
        //Init the VAO for the buffers, the Vertex Buffers will be Identical 
  private void initializeVAO()
   {
      //Bind the VAO
     glBindVertexArray(vertexArrayHandle);
     
      //Bind the Vertex Buffer and indicate where the Vertex are
     glEnableVertexAttribArray(0);
      glBindBuffer(GL_ARRAY_BUFFER, vertexBufferHandle);
      glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
     
      //Bind the Index Buffer
     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferHandle);
      glBindVertexArray(0);
   }

4  Java Game APIs & Engines / OpenGL Development / Re: The need of VAOs and minor confusion on: 2014-01-14 03:25:02

There's nothing wrong with this code. Updating the data of a buffer does not affect the VAO in any way. Neither glBindBuffer() or glBufferData() modify the VAO, so you can update the buffer at any time, even when the VAO is not bound. The VAO just knows which buffers should be read and how the data should be interpreted, not the actual data in the buffer.


I was kinda hoping you'd come back and say yes haha

The reason I asked if it was wrong and if the VAO bind replayed commands is because nothing appears on my screen with that code. It would make sense if that was the case, since it would have already looked at the VBO bound.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
//Code that does not render the quad(s) to the screen
public void render()
{
      //Use the shader program
     glUseProgram(shaderProgramHandle);
     
      //Get the Uniform for the MVP shader
     glUniformMatrix4(matrixBufferHandle, false, mvpBuffer);
     
      //Enable the VAO and its attributes
     glBindVertexArray(vertexArrayHandle[useBuffer]);
     
                //Attempt to bind data to the VBO; Not sure why this fails to draw anything on screen
     glBindBuffer(GL_ARRAY_BUFFER, vertexBufferHandle[useBuffer]);
      glBufferData(GL_ARRAY_BUFFER, vertexBuffer, GL_STREAM_DRAW);
     
      GL11.glDrawElements(GL_TRIANGLES, indexDrawCount, GL11.GL_UNSIGNED_INT, 0);
      glBindVertexArray(0);
     
      useBuffer = 1 - useBuffer;
   }


I can only get something on my screen if I use my 'static' (Called before anything; in a class constructor) init method, where glBindBuffer and glBufferData are inside

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  
public void initDebugBuffers()
   {
     
      vertexBuffer.clear();
      int x = 0;
      int y = 0;
     
      Random random = new Random();
     
      //X and Ys for the Quad; The Z is set to 1.0f
     for(int i = 0; i < MAX_QUADS; i++)
      {
         x = random.nextInt(800);
         y = random.nextInt(600);
         draw(x, y, 32, 32);
      }
     
      //Flip the buffer
     vertexBuffer.flip();
     
      //Bind the vertex buffer's data
    //Gets Quad to appear on screen, flickers but that is because we are only
    //binding the data to one of the two VBOs. (vertexBuffer data is used in both handles)
    //The VBO handles point to the same data spot; done for test purposes
    //Comment out and nothing will appear on screen (the buffer binds are in the render
    //method when the below is commented out)
     glBindBuffer(GL_ARRAY_BUFFER, vertexBufferHandle[0]);
      glBufferData(GL_ARRAY_BUFFER, vertexBuffer, GL_STATIC_DRAW);

      //Indices for the Quad
     indexDrawCount = MAX_INDEX_COUNT;
      indexBuffer.clear();
     
      for(int i = 0, j = 0;  i < MAX_QUADS; i++, j+= 4)
      {
         indexBuffer.put(j);
         indexBuffer.put(j + 1);
         indexBuffer.put(j + 2);
         indexBuffer.put(j + 3);
         indexBuffer.put(j);
         indexBuffer.put(j + 2);
      }
      indexBuffer.flip();
     
      //Bind the index buffer's data
     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferHandle);
      glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexBuffer, GL_STATIC_DRAW);

     
   }


Am I'm missing something? The only thing that I can think of is that my VBO handles in my init VAO method are not set up right. That they are pointing to invalid data. But that really does not make much sense to me either since I can bind the data in the static method, where at that point both VAOs are disabled

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
   private void initializeVAO()
   {
      //Bind the first VAO
     glBindVertexArray(vertexArrayHandle[0]);
      glEnableVertexAttribArray(0);
      glBindBuffer(GL_ARRAY_BUFFER, vertexBufferHandle[0]); //The first Vertex Buffer handle that should be used
     glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferHandle);
      glBindVertexArray(0);
     
      //Bind the second VAO
     glBindVertexArray(vertexArrayHandle[1]);
      glEnableVertexAttribArray(0);
      glBindBuffer(GL_ARRAY_BUFFER, vertexBufferHandle[1]); //The second Vertex Buffer handle that should be used
     glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferHandle);
      glBindVertexArray(0);
   }

5  Java Game APIs & Engines / OpenGL Development / Re: The need of VAOs and minor confusion on: 2014-01-13 03:20:39
Ok cool! Kinda of sucky about the tricky drivers though

Can we go back to the VAOs, while I under stand I should just be binding my VAO. What if my data is not static or I need to swap between buffers I fill on the fly?

I read that I need to use multiple VAOs if I wanted to implement a multiple VBO system; I assume this applies to a double buffer or Mapping system
So for example lets say we have / want a double buffer system. So we make our VAOs like so
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
   private void initializeVAO()
   {
      //Bind the first VAO and vertexBuffer handle
     glBindVertexArray(vertexArrayHandle[0]);
      glEnableVertexAttribArray(0);
      glBindBuffer(GL_ARRAY_BUFFER, vertexBufferHandle[0]);  //Handle to second vertex buffer; Data in there is dynamic and changes each frame
     glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferHandle); //No need for 2 index buffer handles; Contain the same data and is static
     glBindVertexArray(0);

      //Bind the second VAO and vertexBuffer handle
     glBindVertexArray(vertexArrayHandle[1]);
      glEnableVertexAttribArray(0);
      glBindBuffer(GL_ARRAY_BUFFER, vertexBufferHandle[1]); //Handle to second vertex buffer; Data in there is dynamic and changes each frame
     glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferHandle); //No need for 2 index buffer handles; Contain the same data and is static
     glBindVertexArray(0);
   }


Where our render method looks like
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
   public void endRender()
   {
      //Use the shader program
     glUseProgram(shaderProgramHandle);
     
      //Get the Uniform for the MVP shader
     glUniformMatrix4(matrixBufferHandle, false, mvpBuffer);
     
      //Enable the VAO and its attributes
     glBindVertexArray(vertexArrayHandle[useBuffer]);
     
      GL11.glDrawElements(GL_TRIANGLES, indexDrawCount, GL11.GL_UNSIGNED_INT, 0);
      glBindVertexArray(0);
     
      useBuffer = 1 - useBuffer;
   }


In the above code we call glBindVertexArray(vertexArrayHandle[useBuffer]), to bind the VAO we wish to use. Now I'm wondering when I make this call is it executing the commands set up in the init VAO method?

Maybe I'm thinking about this wrong but if it is calling them in order, replaying those commands. How does one change the Buffer data on the fly?
For example I know this does not work but I'm hoping this will make sense out of what I'm asking

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
public void endRender()
   {
      //Use the shader program
     glUseProgram(shaderProgramHandle);
     
      //Get the Uniform for the MVP shader
     glUniformMatrix4(matrixBufferHandle, false, mvpBuffer);
     
      //Enable the VAO and its attributes
     glBindVertexArray(vertexArrayHandle[useBuffer]);

           
                //Does not work but the idea of doing this. How?
               //Bind the buffer handle and VBO to use
     glBindBuffer(GL_ARRAY_BUFFER, vertexBufferHandle[useBuffer]);
      glBufferData(GL_ARRAY_BUFFER, vertexBuffer[useBuffer], GL_STREAM_DRAW);


      GL11.glDrawElements(GL_TRIANGLES, indexDrawCount, GL11.GL_UNSIGNED_INT, 0);
      glBindVertexArray(0);
     
      useBuffer = 1 - useBuffer;
   }

6  Java Game APIs & Engines / OpenGL Development / Re: The need of VAOs and minor confusion on: 2014-01-11 19:59:23
Ok I think I got it

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
   private void initializeVAO()
   {
      //Bind the VAO
     glBindVertexArray(vertexArrayHandle);
      glEnableVertexAttribArray(0);
     
      //Bind the Vertex Buffer and indicate where the Vertex are
     glBindBuffer(GL_ARRAY_BUFFER, vertexBufferHandle);
      glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
     
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferHandle);
     
      glBindVertexArray(0);
   }


Is there a way to force a certain min openGL context? Can I force my app to only allow a openGL 3.0 or better context?
7  Java Game APIs & Engines / OpenGL Development / Re: The need of VAOs and minor confusion on: 2014-01-11 18:07:09
I see so I really should be doing this

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  
   private void initializeVAO()
   {

                //Create and generate the VAO
     IntBuffer vertexArrayBuffer = BufferUtils.createIntBuffer(1);
      glGenVertexArrays(vertexArrayBuffer);      
      vertexArrayHandle = vertexArrayBuffer.get(0);

                //Create and generatate the Vertex Buffer and  Index BUffer
     IntBuffer buffers = BufferUtils.createIntBuffer(2);
      glGenBuffers(buffers);
      vertexBufferHandle = buffers.get(0);
      indexBufferHandle = buffers.get(1);

      //Bind the VAO and set up the Vertex Attributes
     glBindVertexArray(vertexArrayHandle);
      glEnableVertexAttribArray(0);
     
      //Bind the Vertex Buffer and indicate where the Vertex are
     glBindBuffer(GL_ARRAY_BUFFER, vertexBufferHandle);
      glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
     
      glBindVertexArray(0);
   }

   public void Render()
   {
      //Use the shader program
     glUseProgram(shaderProgramHandle);
     
      //Get the Uniform for the MVP shader
     glUniformMatrix4(matrixBufferHandle, false, mvpBuffer);
     
      //Enable the VAO and its attributes
     glBindVertexArray(vertexArrayHandle);
     
      //glDrawArrays(GL_TRIANGLES, 0, 3);
     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferHandle);
      GL11.glDrawElements(GL_TRIANGLES, indexDrawCount, GL11.GL_UNSIGNED_INT, 0);
     
      glBindVertexArray(0);
   }


The index buffer call is that correct? In the sense that it is separate from the VAO

Also if I'm loading in data every frame or so through a batching system, I assume I would need to switch between multiple VAOs every Nth frame correct?
8  Java Game APIs & Engines / OpenGL Development / The need of VAOs and minor confusion on: 2014-01-11 17:07:56
I was going over my render method and I started thinking. Do I need a VAO? All the tutorials I have looked at go over VAOs, but do I need them if my data is dynamic (changing every frame)?

I understand that VAO is a state object that is s supposed to hold the 'state' of Vertex Array Pointers for the VBOs I bind and etc. That if I bind a VAO and then use glEnableAttribPointer, bind a VBO, and glVertexAttribPointer to pointer to the VBO data a record is saved into the VAO. Where I can call the VAO bind function in my render method and everything will know how to draw.

But my confusion kind of comes in when the data I'm using is dynamic and changing every frame. If I have my render method as:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
   public void render()
   {
      //Use the shader program
     glUseProgram(shaderProgramHandle);
     
      //Get the Uniform for the MVP shader
     glUniformMatrix4(matrixBufferHandle, false, mvpBuffer);
     
      //Enable the VAO and its attributes
     glBindVertexArray(vertexArrayHandle); //Can comment out and has no effect; Never bound until this point
     glEnableVertexAttribArray(0);
     
      //Bind the Vertex Buffer and indicate where the Vertex are
     glBindBuffer(GL_ARRAY_BUFFER, vertexBufferHandle);
      glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
     
      //glDrawArrays(GL_TRIANGLES, 0, 3);
     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferHandle);
      GL11.glDrawElements(GL_TRIANGLES, indexDrawCount, GL11.GL_UNSIGNED_INT, 0);
     
      glDisableVertexAttribArray(0);
   
   }


Do I really need the VAO? Would my app be faster with out them or with them? Or am I doing a bad 'thing' rebinding all the Vertex Attributes and etc every single time my render method is called? Should I only be rebinding the VAO, does this change (The rebinding) if my data is dynamic?
9  Java Game APIs & Engines / OpenGL Development / Re: Questions about VBOs / IBOs on: 2014-01-09 00:20:43
I was under the impression that you had lots of experience under your belt, given that you came from C/DirectX.

There are quite a few conceptual errors in your latest code dump (like pushing more texcoords than vertices, mapping without binding specific VBOs, combining unsynced mapping and orphaning, never writing indices in your index buffer, interleaving vertex attributes in overlapping mapped buffers, while writing into each sequentially, using offets when using distinct VBOs for your attributes, mapping teeny tiny ranges, not even enough to hold one quad). I'd advise you to go all the way back to Vertex Arrays (not VBOs, not mapping them, and not even close to unsynced mapped VBOs) and get it working from there (starting with 1 triangle or quad) -- then work your way up again, if the need arises.

Coming from C++ / DirectX has no true ground when dealing with openGL. Its a different API, things are handled differently. Yes, concepts are the same but implementation is another thing

Pushing more Text coords
This is my fault, when I think of Vertex I think of the Vertex Struct I can do in C++/DirectX. Since I can't do this in java/openGL, then you are right I am missing 8 more puts (The remaining X/Y coords and the Z coord)

Should be fixed in the above code

Mapping without binding specific VBOs
Maybe I am not thinking of this right, but I would do this in the constructor / init of the Batcher. Please correct me if I'm wrong, but I can/only need to do this (Bind the specific buffers) once right? Or does this need to be done multiple times? Also am I not allowed to bind multiple buffers at once? Again maybe interleaving is the solution to this

Combining unsynced map and orphaning
I'm not too sure about this one, as this topic is about implementing orphaning or a double buffer.
I appreciate the time you're taking to explain this, unfortunately I guess things are not clicking

Not filling the index buffer
The code is just meant to show the three methods (endRender, beginRender, addDrawData) and how they work together. My idea was to have the index buffer filled once the Batcher class was created. There is no need in my mind to have this refilled with the same data value each time, since there is a max size for each buffer

interleaving vertex attributes in overlapping mapped buffers, while writing into each sequentially
I don't think I do this? I mentioned that maybe I need to do this because of the mapping call and use of UV coords

using offets when using distinct VBOs for your attributes
I don't think interleaving? No need for offset until I do so right?

mapping teeny tiny ranges / not even enough to hold one quad
I'm confused about this one, could you explain? My comments say that the vertex buffer would hold 10000 verts and the UV buffer would hold the required amount. Maybe this was in relation to the first issue

Now with that being said, I do see one thing that is wrong, and that is the glMapRange length param usage (pertaining to the latest code). What if I don't know how much I'm going to map at a given time? What if I want to map until I say so (eg because I have ran out fo room or I have to swap a texture)? How is a undefined length done?

That kinda kills the idea of mapping a range though, so would I then use just glMapBuffer? Whats the difference in terms of performance?
10  Java Game APIs & Engines / OpenGL Development / Re: Questions about VBOs / IBOs on: 2014-01-08 03:04:37
Don't map/unmap your buffer every time you add a quad. Map it once, and fill it with as much as fits in it.

Yea, I woke up this morning and though about it was like 'ooo you messed up' haha

So like you said, I think I should really be doing this. The on thing I;'m not too sure about is the unmap part since there is no specific link to the buffer I want to unmap.
Maybe I'm missing something or maybe I have to interleave them for this to work?

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  
//My main draw method
public void Render()
{
   batcher.beginRender(); //Sanity Checks if we are calling the right methods (Don't call endRender before begin and etc

//Queue the VBO with draw data!
  for(int i = 0; i < 6000; i++)
           batcher.draw(randX(), randY(), 32.0f, 32.0f);

//End the render; draw whatever we got in the VBO
  batcher.endRender();
}


/* All below apart of a Batcher Class; Has a Vertex Buffer and UV Buffer set to GL_STATIC_DRAW. Has a index buffer that is static and filled
from the start based on the max size of the vertex buffer. Lets assume its 10000 verts */


//My begin render method
public void beginRender()
{

   /*Sanity Checks */

   //Map the vertex buffer
  vertexBuffer = glMapBufferRange(GL_ARRAY_BUFFER, vertexBufferPosition, 12, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT, null).asFloatBuffer();

   //Map the vertex buffer
  uvBuffer = glMapBufferRange(GL_ARRAY_BUFFER, uvBufferPosition, 8, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT, null).asFloatBuffer();

}

//My Draw method, get everything to the screen
public void endRender()
{
   //Bind the texture
  glActiveTexture(GL_TEXTURE0);
   glBindTexture(GL_TEXTURE_2D, currentTexture);
   glUniform1i(texture, 0);

   //Enable the vertex buffer
  glEnableVertexAttribArray(0);
   glBindBuffer(GL_ARRAY_BUFFER, vertexBufferHandle);
   glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);

   //Enable the uv buffer
  glEnableVertexAttribArray(1);
   glBindBuffer(GL_ARRAY_BUFFER, uvBufferHandle);
   glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 0);

   //Draw everything needed based n index buffer
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferHandle);
   GL11.glDrawElements(GL_TRIANGLES, indexCount, GL11.GL_UNSIGNED_INT, 0 );

   //Safety disable
  glDisableVertexAttribArray(0);
   glDisableVertexAttribArray(1);
}


//My put some data into the VBOs method; places data into the Vertex and UV vbo; Checks if orphans need making
public void addDrawData(float x, float y, float width, float height)
{
   //Check if we will be over the limit
  if(vertexBufferPosition + 12 > vertexBufferMax)
   {
       //Unmpa the buffers; called twice: one for the vertex buffer one for the uv buffer; May need to interleave?
     glUnmapBuffer(GL_ARRAY_BUFFER);
      glUnmapBuffer(GL_ARRAY_BUFFER);

      //End the render; draw stuff
     endRender();

      //Orphan the buffer
     glBufferData(GL_ARRAY_BUFFER, 0, GL_STREAM_DRAW);
      vertexBufferPosition = 0;
      indexCount = 0;

      //Re map the buffers
     vertexBuffer = glMapBufferRange(GL_ARRAY_BUFFER, vertexBufferPosition, 12, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT, null).asFloatBuffer();

      uvBuffer = glMapBufferRange(GL_ARRAY_BUFFER, uvBufferPosition, 8, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT, null).asFloatBuffer();
   }

   //Put the 4 verts (x, y, and z coords [ Z coords defaults to 1.0f ]) for a quad
  //Vert1
  vertexBuffer.put(x); vertexBuffer.put(y); vertexBuffer.put(1.0f);
   
   //Vert 2
  vertexBuffer.put(x+width); vertexBuffer.put(y);vertexBuffer.put(1.0f);
 
   //Vert 3
  vertexBuffer.put(x + width); vertexBuffer.put(y + height); vertexBuffer.put(1.0f);

   //Vert 4
  vertexBuffer.put(x); vertexBuffer.put(y+height);vertexBuffer.put(1.0f);

   //Tex Coord for Vert 1
  uvBuffer.put(0); uvBuffer.put(0);

   //Tex Coord for Vert 2
  uvBuffer.put(0); uvBuffer.put(1);

   //Tex Coord for Vert 3
  uvBuffer.put(0); uvBuffer.put(1);

   //Tex Coord for Vert 4
  uvBuffer.put(1); uvBuffer.put(1);

   //Add 12; because 4 vertex (With X Y Z coords) per quad
  vertexBufferPosition += 12;

   //Add 8; because 2 per vertex and there are 4 vertex per quad
  uvBufferPosition += 8;

   //Add 6; because of 6 indices per quad
  indexCount += 6;
}


11  Java Game APIs & Engines / OpenGL Development / Re: Questions about VBOs / IBOs on: 2014-01-07 02:47:54
You might be correct Cheesy

Okay, so while I'm still a little uneasy about glMapBuferRange. I figure I give it a try, now I'm not sure if I did this right but...
This is what I got, feel free to tell be I'm going about this all wrong.

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  
//My main draw method
public void Render()
{
   batcher.beginRender(); //Sanity Checks if we are calling the right methods (Don't call endRender before begin and etc

//Queue the VBO with draw data!
  for(int i = 0; i < 6000; i++)
           batcher.draw(randX(), randY(), 32.0f, 32.0f);

//End the render; draw whatever we got in the VBO
  batcher.endRender();
}


/* All below apart of a Batcher Class; Has a Vertex Buffer and UV Buffer set to GL_STATIC_DRAW. Has a index buffer that is static and filled
from the start based on the max size of the vertex buffer. Lets assume its 10000 verts */

//My Draw method, get everything to the screen
public void endRender()
{
   //Bind the texture
  glActiveTexture(GL_TEXTURE0);
   glBindTexture(GL_TEXTURE_2D, currentTexture);
   glUniform1i(texture, 0);

   //Enable the vertex buffer
  glEnableVertexAttribArray(0);
   glBindBuffer(GL_ARRAY_BUFFER, vertexBufferHandle);
   glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);

   //Enable the uv buffer
  glEnableVertexAttribArray(1);
   glBindBuffer(GL_ARRAY_BUFFER, uvBufferHandle);
   glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 0);

   //Draw everything needed based n index buffer
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferHandle);
   GL11.glDrawElements(GL_TRIANGLES, indexCount, GL11.GL_UNSIGNED_INT, 0 );

   //Safety disable
  glDisableVertexAttribArray(0);
   glDisableVertexAttribArray(1);
}


//My put some data into the VBOs method; places data into the Vertex and UV vbo; Checks if orphans need making
public void addDrawData(float x, float y, float width, float height)
{
   //Check if we will be over the limit
  if(vertexBufferPosition + 4 > vertexBufferMax)
   {
      //End the render; draw stuff
     endRender();

      //Orphan the buffer
     glBufferData(GL_ARRAY_BUFFER, 0, GL_STREAM_DRAW);
      vertexBufferPosition = 0;
      indexCount = 0;
   }

   //Map the vertex buffer
  vertexBuffer = glMapBufferRange(GL_ARRAY_BUFFER, vertexBufferPosition, 4, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT, null).asFloatBuffer();

   vertexBuffer.put(x);
   vertexBuffer.put(y);
   vertexBuffer.put(x + width);
   vertexBuffer.put(y + height);

   glUnmapBuffer(GL_ARRAY_BUFFER);

   //Map the vertex buffer
  uvBuffer = glMapBufferRange(GL_ARRAY_BUFFER, uvBufferPosition, 8, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT, null).asFloatBuffer();

   uvBuffer.put(0);
   uvBuffer.put(0);

   uvBuffer.put(0);
   uvBuffer.put(1);

   uvBuffer.put(0);
   uvBuffer.put(1);

   uvBuffer.put(1);
   uvBuffer.put(1);

   glUnmapBuffer(GL_ARRAY_BUFFER);

   //Add 4; because 4 vertex per quad
  vertexBufferPosition += 4;

   //Add 8; because 2 per vertex and there are 4 vertex per quad
  uvBufferPosition += 8;

   //Add 6; because of 6 indices per quad
  indexCount += 6;
}


Also is my double buffer idea is correct? I have never set one up before so I'm not sure if I got the implementation down
12  Java Game APIs & Engines / OpenGL Development / Re: Questions about VBOs / IBOs on: 2014-01-06 02:21:55
Since DirectX and OpenGL is so much more different and because you have so many questions I highly suggest reading an up-to-date book about OpenGL.
Sadly, they're pretty hard to get but from what I hear OpenGL Superbible's 6th edition is quite good. Also OpenGL 4.0 Shading Language Cookbook is a great piece, however, they're quite expensive. Cry

I have the openGL superbible 5th edition, but like you mention its up to date Sad
Also for me books are hit and miss. They are great for learning how to do something, but I feel like they don't get down on the nitty gritty stuff like I'm looking for imo

Could you explain what do you mean by "blocking calls"?

By blocking calls I mean the mutex lock (on hardware level) that is done by the GPU when it is using a buffers data. I understand that the GPU can stall and shutout the CPU until its done finishing the commands it is running wiht the buffer.

I don't know how exactly
glMapBuffer()
works so I can't help you with that one.
OpenGL contexts are automatically double buffered and you're always drawing to the back buffer (from default). After you're done with your frame you can swap the buffers (LWJGL automatically does this for you with
Display.update()
) so the user will see the rendered frame in the front buffer, and you can work on the back buffer that is currently filled with the frame before (that's why you have to clear the color/depth/stencil buffers so you clear those from the current back buffer).

We have misunderstanding here (totally my fault), when I mean double buffer I'm talking about using 2 Vertex Buffer Objects. In the sense that is described in this article from Apple https://developer.apple.com/library/mac/documentation/graphicsimaging/conceptual/opengl-macprogguide/opengl_designstrategies/opengl_designstrategies.html#//apple_ref/doc/uid/TP40001987-CH2-SW8

The idea behind it is pretty simple in all honesty
You have 2 Vertex Buffers and you alternate between them each frame. So beginning with frame 1 you have 2 blank buffers. You fill one and send it to the GPU for drawing. Then on the next frame you fill the next Vertex Buffer, while the GPU is still working on the first one. By doing this you are supposed to be able to prevent the GPU from locking down on the Vertex Buffers. I have read that this works great on both ATI and Nvidia cards


glMapBuffer has the biggest overhead of all.

glMapBufferRange with UNSYNCHRONIZED flag has the least overhead of all VBO operations that move data around.

as it's unsynchronized (the driver doesn't lock anything at all) you need a queue of at least 4-5 VBOs and take/release one every frame, or you'll get corrupted vRAM.

At both Riven and  Panda, since you guys kinda go together on this one Cheesy

I have read that you can do a technique called 'orphaning' using either the glMapBuffer call or the glMapBufferRange call

Where the idea is that when using the glMapBuffer call, you use glBindBuffer with a null pointer to the Vertex Buffer. And what this does is, its supposed to, tell the driver hey give me a spot in mem that I can use because I need it now. And then y follow up with glMapBuffer() and place all your data in the vertex buffer. Send it off to the GPU and etc. This allows you to have multiple Vertex Buffers in flight where they then can be processes by the GPU. I heard you can do this with the glMapBufferRange call to using some a couple of flags, but I have heard (using glMapBufferRange) can be a real performance killer if you do it wrong.


That is why I'm kinda leaning to the Double VBO approach, am not not sure how I should be setting it up I guess. My ideas on implimentation are shady. As anyone has some experience with this?

I was thinking some thing like

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  
public void endRender()
{
   /* Other required items above, core VBO stuff below*/

   //Enable the Vertex Buffer, bind it for the Shader
  glEnableVertexAttribArray(0);
   glBindBuffer(GL_ARRAY_BUFFER, currentVertexBuffer);
   glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);

   //Enable the UV Buffer, bind it for the Shader
  glEnableVertexAttribArray(1);
   glBindBuffer(GL_ARRAY_BUFFER, currentUvBuffer);
   glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 0);

   //Bind the STATIC Index Buffer (Since it is always the same slot wise)
  //Draw the number of elements needed
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
   GL11.glDrawElements(GL_TRIANGLES, numberOfIndex, GL11.GL_UNSIGNED_INT, 0 );

   /Disable all the attributes for safty
   glDisableVertexAttribArray(0);
   glDisableVertexAttribArray(1);
   glDisableVertexAttribArray(2);

   //Swap the buffers
  bufferToUse = !buffertoUse;
   currentVertexBuffer = vertexBuffers.get(bufferToUse);
   currentUvBuffer = uvBuffers.get(bufferToUse);
}

public void addDrawData(/*Draw data params */)
{

   if(/* The vertex buffer limit is going to be over  or a texture swap is needed*/)
   {
      //Send stuff to the GPU
     endRender();
     
      //Reset / clear the buffer. Prepare it for writing
     currentVertexBuffer.clear();
      currentUvBuffer.clear();
   }
   
   // Add the data for drawing into the buffer
  currentVertexBuffer.put(/*Some Vertex data for vert 1*/);
   currentVertexBuffer.put(/*Some Vertex data for vert 2*/);
   currentVertexBuffer.put(/*Some Vertex data for vert 3*/);
   currentVertexBuffer.put(/*Some Vertex data for vert 4*/);
   
   currentUvBuffer.put(/*Some UV data for vert 1*/);
   currentUvBuffer.put(/*Some UV data for vert 2*/);
   currentUvBuffer.put(/*Some UV data for vert 3*/);
   currentUvBuffer.put(/*Some UV data for vert 4*/);
}
13  Java Game APIs & Engines / OpenGL Development / Re: Questions about VBOs / IBOs on: 2014-01-04 20:54:03
Before things go in the wrong direction, it kinda seems like I'm implying that I have no knowledge of how openGL works

I know about VBOs, VAOs, IBOs, and etc. I know DirectX and openGL are very different.

My question, unfortunately, is all over the place. I really want to know from a performance standpoint for 2D work. What is the best way or what way should I be sending data to the GPU?

In the sense like Troubleshoots pointed out, I would want to use the usage flag GL_STREAM_DRAW, because I plan for data to change at least every frame. BUT also I want to know everyone thoughts on the type of buffer system to use

When I mentioned DirectX and gave an example that was a circular buffer. Essentially we were always able to stream data to the GPU and it would prevent blocking calls. Since we are able to get a new location in memory to use. Well I'm not sure if this is possible to do in openGL, not possible in that there are 'special' glMapBuffer() params  or something that says if we are out of space in the buffer just give us a new one. If it is awesome and how/should can it be done?

If not then lets talk about a double buffer system, where we load data into one, send it off to the GPU, fill the secondary buffer with data, and rinse and repeat.

I guess what I'm truly asking at the end of the day is if I cannot make a circular buffer (With 'special' params or etc), how should I be doing a double buffer system? Not in the sense of what needs to be done at high level, but what are things I need to worry about?

How should my openGL calls look? When am I going to be blocked by the GPU? Things of that nature
14  Java Game APIs & Engines / OpenGL Development / Questions about VBOs / IBOs on: 2014-01-04 18:42:32
I was wondering about this and I'm hoping you guys can help me out.
I hope I can explain this, so please bare with me.

I come from the world of DirectX 11 where you can use / setup Dynamic Vertex and Index Buffers.
Which have 'lock flags', these log flags basically tell the GPU how data is going to be treated. Well when you set up Dynamic Vertex Buffers and Index Buffers you use a DISCARD and NOOVERWRITE flag. The DISCARD flags says trash everything in the buffers, we don't care about it. Where as the NOOVERWRITE flag says anything that is already in use, you can't have.

Using these both you can create a circular buffer system. since the DISCARD flag does this special thing that creates a new place in mem for the GPU to use. Something like the below is a way to get a circular buffer:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
//Code done when needing to draw, places the draw data directly into the vertex buffer
if(vertexBufferPosition + vertexdPerQuad > maxVertexAllowed)
{
        //Says that we are done manipulating draw data
  batchContext->Unmap(vertexBuffer, 0);

        //Go ahead aand send everything of to the GPU and draw all that needs to be ddrawn
  batchContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
   batchContext->DrawIndexed(indexCount, 0, 0);
   indexCount = 0;

        //Reset our stuff and since we were out of space, give us another spot in mem to use (Setting the mapFlag to DISCARD)
  vertexBufferPosition = 0;
   mappingFlag = D3D11_MAP_WRITE_DISCARD;

        //Relock the buffer so we can add more GPU data, also since we are using a fresh buffer, set the lockflag to NOOVERWRITE
  batchContext->Map(vertexBuffer, 0, mappingFlag, 0, &mapVertexResouce);
   mappingFlag = D3D11_MAP_WRITE_NO_OVERWRITE;

}

//Draw data placed directly into the vertex buffer
addDrawData(x,y,width,height);


SO my question, can this be done in openGL? Is there such things as lockflags and mapping?
I understand how to place data into a vertex buffer based on some tutorials, but that was for static buffers

How should I be placing data into a buffer when it needs to change every frame or so? For things such as a SpriteBatcher or Partical emitter? I should also mention I'm trying to target openGL 3.3 and up
15  Java Game APIs & Engines / OpenGL Development / Matrix Questions and Perspective on: 2013-12-27 05:49:44
Hey so I have a few questions about Shaders, Matrices, and the perspective projection.

I'm trying to change the camera for a Triangle I'm rendering
So I have a vertex Shader, that takes in a MVP matrix
1  
2  
3  
4  
5  
6  
7  
#version 330 core
layout(location = 0) in vec3 position;
uniform mat4 MVP;
void main()
{
     gl_Position = MVP * vec4(position, 1);
}


When I attempt to set the projection matrix to a calculated perspective [ 45.0f FOV, 4.0/3.0 aspect, .01f nearPlane, 100.0 farPlane].
I get nothing on the screen

If I do nothing to my Matrix, the triangle shows since I did nothing with my Matrix (They're all just identities)
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
//Works but the Projection Matrix and everything is set to defaults :(
matrixID = GL20.glGetUniformLocation(programID, "MVP");
Matrix4f projection = new Matrix4f();
Matrix4f view = new Matrix4f();
Matrix4f model = new Matrix4f();

Matrix4f MVP = Matrix4f.mul(view, model, null);
Matrix4f.mul(projection, MVP, MVP);
mvpBuffer = BufferUtils.createFloatBuffer(16);
MVP.store(mvpBuffer);
mvpBuffer.flip();


So my question is there something 'special' I have to do to use a perspective matrix?

Using this code I get nothing on the screen
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
Matrix4f projection = projectionPerspectiveMatrix(45.0f, 4.0f/3.0f, 0.01f, 100.0f);

//Full method
public Matrix4f projectionPerspectiveMatrix(float fieldOfView, float aspectRatio, float nearPlane, float farPlane)
{
   Matrix4f mat = new Matrix4f();
   float yScale = coTan(degreeToRadians(fieldOfView / 2.0f));
   float xScale = yScale / aspectRatio;
     
   mat.m00 = xScale;
   mat.m11 = yScale;
   mat.m22 = (farPlane + nearPlane) / (nearPlane - farPlane);
   mat.m23 = -1;
   mat.m32 = (2.0f * farPlane * nearPlane) / (nearPlane - farPlane);
     
   return mat;
}
16  Java Game APIs & Engines / OpenGL Development / Matrix Setting? on: 2013-12-26 23:59:05
Quick question, how do you 'set' a matrix when using something like glPerspective or glOrtho?

I'm coding for openGL 3.3, so I'm sure if using glMatrixMode(GL_PROJECTION) and etc is the right thing to do
In C++ openGL (All the tutorial's I'm looking at are in C++) you can do, but how is this done using LWJGL?

1  
2  
//C++ code of setting a projection matrix
glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f);
17  Java Game APIs & Engines / OpenGL Development / [Solved! - Ignore] Triangle and I... not friends on: 2013-12-26 17:19:12
Nevermind! My shader program was broken I was setting GL_Position.x to 1 when it should have been using GL_Position.w

EDIT:
I got the triangle to appear on screen Cheesy
BUT it only appears when I do not use the Shader Program Sad

Did I miss something in my Render Method or Shader set up?
http://pastebin.java-gaming.org/a3b06098d74



I'm trying to display a simple triangle in openGL using a vertex/fragment shader. but I can get anything to appear on the screen Sad

Can someone tell me where I went horribly wrong
http://pastebin.java-gaming.org/6a3b096797d

I should probably mention, my shaders compile just fine (No errors on compiling or linking)
18  Java Game APIs & Engines / OpenGL Development / Re: Back to openGL on: 2013-12-26 06:29:35

Most computers today support OpenGL 2.1 and it's pretty safe to make that your base supporting version. Shaders were introduced in 2.0, so you're still fine. It's only 3.1 that everything fixed function was deprecated. I would suggest you learn modern OpenGL 3.3 first, as it becomes much easier in my opinion to learn older versions.


I agree, seeing as hardware is getting better by the day and Win XP is getting its support dropped in April

Also is there some hint as to what is depreciated? I see that I need to import things like org.lwjgl.opengl.GL15; in order to use glGenBuffers() something that seems to be used in 3.X and up
19  Java Game APIs & Engines / OpenGL Development / Re: Back to openGL on: 2013-12-26 06:08:54
Nope, vertex shader input attributes cannot be objects. Attributes also don't have to be only vertex, color, or index. That link you posted shows deprecated functions glVertexPointer and glColorPointer. Those were the old ways of doing things. Now, OpenGL doesn't care what data is position or color, they're all inputs to your vertex shader! You control how the data is sent and processed, and how the output results.

This actually brings up a really rough spot with me. So I know that we are in the OpenGL 4.X range in terms of what is 'up to date'. I know that 2.1 and down is legacy. And Then 3.0 becomes all shaders (No more fixed function pipeline). So in your opinion ( or anyone that wants to weigh in on this) I kinda want to support legacy hardware, but do you think I should just skip them and go on to 3.0? I mean is it a big impact?

I don't know of any resources that teach 2D OpenGL only, as it's best to usually learn how to do 3D with it and then 2D becomes simple.

A really good tutorial I recommend that covers modern core OpenGL would be this: www.arcsynthesis.org/gltut
That tutorial's code is in C++ though, so I ported it to Java+LWJGL: www.bitbucket.org/ra4king/lwjgl-shader-tutorials/
If you're not interested in focusing on 3D much, then I would recommend going through chapters 1-7 and 14-16 only.

Another excellent resource is our own Davedes's tutorials: https://github.com/mattdesl/lwjgl-basics/wiki

No worries on this, my plan was to use textured quads all along. Yea I'm seeing a lot of tutorials are in C++, nothing to bad. But still a bit of a pain to 'convert'


Traditionally, state in OpenGL has been global. And when I say "state", I'm talking about active textures, active buffers and so on. You can only have one VBO set as each active target, like GL_ARRAY_BUFFER and GL_ELEMENT_BUFFER, at any given time. So when using multiple buffers, you change the state for each target every time you need to render a different buffer. That means multiple calls to change state, which can become expensive.

VAOs allow you to make multiple state changes with one call. You associate a number of related VBOs (such as a vertex buffer and an index buffer) and their state with a VAO, then when its time to render you only activate the VAO. That way, you don't need to make multiple calls to set up the state of each VBO target. The best way to understand it is to avoid thinking of a VAO as an object (vertex array object is a horribly confusing name). Think of it more as a marker, or in index into an array of states.

In C or C++, you could do this. The memory layout of a struct (or C++ class) declared like your Vertex class would be the same as that of an array of six floats. So you could use an array of Vertex objects and call glVertexAttribPointer to set up the offsets for each attribute. Then you would wind up with what they call "interleaved buffers". In Java, you could declare a vertex class like this, but because of the nature of the OpenGL bindings like LWJGL, you still would have to fill a ByteBuffer with the individual values. You wouldn't be able to pass the object directly to OpenGL.

Dear god that is a horrible name... I thought these were separate objects the whole time

And the part about the struct, yeah I wish you could do this, when I made a SpriteBatcher in DX11 that was awesome. You can just pop them in on a Map call and you were good to go
20  Java Game APIs & Engines / OpenGL Development / Re: Back to openGL on: 2013-12-26 05:06:07
An index buffer IS a VBO. A Vertex Array Object doesn't store vertex data, but holds state.

Maybe you should re-learn OpenGL from scratch Smiley

I'm pretty much starting there, I have very scattered knowledge Sad

Can you explain a bit more? I'm looking at this mini tutorial
http://www.java-gaming.org/topics/introduction-to-vertex-arrays-and-vertex-buffer-objects-opengl/24272/view.html

I don't really see them as states (The VAOs). They just seem like I'm making some buffers and telling OpenGL "Hey these are by buffers and this is where they are at". Where are with a VBO I actually have to bind them and declare a usage.

Also I see that there are 3 buffers: Vertex, Color, and index

It is possible to create a buffer that is a object and not primitive?
So I could do something like
1  
2  
3  
4  
5  
class Vertex
{
    float x, y; z;
    float c1, c2, c3;
}
21  Java Game APIs & Engines / OpenGL Development / Back to openGL on: 2013-12-26 03:47:52
Its been a long time since I tried openGL, been wandering around, and now I need to know...

Can you use a Vertex Array Object with a index Buffer? Or can you only use Index Buffers with VBOs?

My goal is to make a 2D game, no 3D plans as of now, I know this does not matter since everything is 3D. But I figure I'd mention it just encase, maybe VAOs are faster than a VBO and Index Buffer when it comes to making a Sprite Batcher
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.

Nickropheliac (15 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (33 views)
2014-08-22 19:31:30

atombrot (41 views)
2014-08-19 09:29:53

Tekkerue (40 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (25 views)
2014-08-16 06:20:21

Tekkerue (37 views)
2014-08-16 06:12:11

Rayexar (72 views)
2014-08-11 02:49:23

BurntPizza (49 views)
2014-08-09 21:09:32
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!