Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Back to openGL  (Read 475 times)
0 Members and 1 Guest are viewing this topic.
Offline noodleBowl

Senior Newbie





« Posted 2013-12-26 04: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
Offline ra4king

JGO Kernel


Medals: 341
Projects: 2
Exp: 5 years


I'm the King!


« Reply #1 - Posted 2013-12-26 05:21:40 »

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

Offline noodleBowl

Senior Newbie





« Reply #2 - Posted 2013-12-26 06: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;
}
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 341
Projects: 2
Exp: 5 years


I'm the King!


« Reply #3 - Posted 2013-12-26 06:36:59 »

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.

VAO's just hold state: which VBO's are used, which attributes they map to, and any index buffers if used.

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

Offline aldacron

Senior Member


Medals: 9
Exp: 16 years


Java games rock!


« Reply #4 - Posted 2013-12-26 06:43:03 »

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.

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.

Quote
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;
}


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.
Offline noodleBowl

Senior Newbie





« Reply #5 - Posted 2013-12-26 07: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
Offline ra4king

JGO Kernel


Medals: 341
Projects: 2
Exp: 5 years


I'm the King!


« Reply #6 - Posted 2013-12-26 07:17:22 »

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?
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.

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
They are separate objects. VBO's store plain old data that you upload. VAO's store which VBO's are being used and how.

And structs can't be used for input attributes. They can, however, be used as uniforms. Smiley

Offline noodleBowl

Senior Newbie





« Reply #7 - Posted 2013-12-26 07: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
Offline ra4king

JGO Kernel


Medals: 341
Projects: 2
Exp: 5 years


I'm the King!


« Reply #8 - Posted 2013-12-26 08:15:40 »

LWJGL groups functions and enums by the version they were introduced in. OpenGL 1.5 (GL15) introduced VBO's. OpenGL 3.X (GL3X) uses and builds on them.

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

 

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

The first screenshot will be displayed as a thumbnail.

CogWheelz (14 views)
2014-07-30 21:08:39

Riven (21 views)
2014-07-29 18:09:19

Riven (14 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (29 views)
2014-07-23 21:07:15

Riven (30 views)
2014-07-23 20:56:16
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!