Sign in to follow this  
coderWalker

OpenGL OpenGL 3.1

Recommended Posts

coderWalker    127
I have been using vertex arrays (ClientSide), however now I am having
the problem that my CPU is not at full usage nor my GPU however the
game still lags. So I have decided to switch to VBO's and Shaders.
Maby the GPU-CPU bandwidth is causing the problem.
My target is to not use any deprecated functions.

I have been looking at the tutorials here:
[url="http://duriansoftware.com/joe/An-intro-to-modern-OpenGL.-Chapter-3:-3D-transformation-and-projection.html"]Tutorial Series[/url]

However it seems it is alot of work to create the matricies, especially
considering these will keep changing.

I know that Sin and Cos are really labor intensive functions,
these calculations below are performed for every vertex right?
Wouldn't this be very slow?

[quote]
const mat3 projection = mat3( vec3(3.0/4.0, 0.0, 0.0), vec3( 0.0, 1.0, 0.0), vec3( 0.0, 0.0, 1.0) ); mat3 rotation = mat3( vec3(1.0, 0.0, 0.0), vec3(0.0, cos(timer), sin(timer)), vec3(0.0, -sin(timer), cos(timer)) ); mat3 scale = mat3( vec3(4.0/3.0, 0.0, 0.0), vec3( 0.0, 1.0, 0.0), vec3( 0.0, 0.0, 1.0) ); gl_Position = vec4(projection * rotation * scale * position.xyz, 1.0); texcoord = position.xy * vec2(0.5) + vec2(0.5); fade_factor = sin(timer) * 0.5 + 0.5;
[/quote]

Here is a screenshot of a game I am going to try and change from OpenGL 1.1 to openGL 3.1:
[img]http://webstrand.comoj.com/pics/bugs/clouds.png[/img]

Thanks

Overall:

Are VBO's faster then Vertex Arrays?

Are Vertex and Fragment Shaders faster than the Fixed Pipeline?

Are vertex shaders called for every vertex?

Is there a better way to do this than use sin() and cos()

Share this post


Link to post
Share on other sites
zacaj    667
Yes, VBOs are faster than vertex arrays. Vertex shaders are called for every vertex, but the matrix is only computed once for the draw call, including sin+cos, so theyre not done per vertex.

Share this post


Link to post
Share on other sites
Trienco    2555
[quote name='zacaj' timestamp='1306717199' post='4817307']
Yes, VBOs are faster than vertex arrays. Vertex shaders are called for every vertex, but the matrix is only computed once for the draw call, including sin+cos, so theyre not done per vertex.
[/quote]

Unfortunately the tutorial doesn't seem to teach that this kind of thing is usually set once as a shader uniform in your application and not done for every single vertex in your shaders main(). Though chances are that GLSL compilers do what every good compiler would do: evaluate these expressions at compile time. Unless it turns out that shader complexity kills the performance, I'd worry more about making it work before making it faster.

Share this post


Link to post
Share on other sites
coderWalker    127
Thanks for the responces!

I have another question, again in the same tutorial they have specified the vertex positions and a seperate VBO for the list of vertex's.

Is it possible just to submit the vertex positions in order?

or...

I am making a Voxel engine in which the cubes have textures (as seen in above pic)
Each vertex is actually used 3 times, because of how it works, so implementing this would help.
Basically I make the data for the GPU by looping threw the blocks and checking if the adjacent block in any direction doesn't exist.
If it doesnt exist it adds it to a vector "vertexBuffer"

How could I adapt this so It creates the vertex position and element lists?

I was thinking a 3d array but that would be a ton slower then it is now.
Then I thought a list, but it having to search if a vertex is already added would get exponentially slower.

Also I am going to add real lighting, so if a vertex is repeated each one will need it's own Normal.
Are these specified with the vertex's or the element array?

Again thanks a ton!

~coderwalker

[b]Current method of Adding a face to buffer:[/b]
[code]
//Left
if (block[position[x-1][y][z]].hard==false)
{
iVertex3dQuad ver;
ver.x1 = x; ver.y1 = y; ver.z1 = z;
ver.x2 = x; ver.y2 = y; ver.z2 = z+1;
ver.x3 = x; ver.y3 = y+1; ver.z3 = z+1;
ver.x4 = x; ver.y4 = y+1; ver.z4 = z;
vertexBuffer.push_back(ver);

fVertex2dQuad tex;
tex.x1 = xMin; tex.y1 = yMin;
tex.x2 = xMin; tex.y2 = yMax;
tex.x3 = xMax; tex.y3 = yMax;
tex.x4 = xMax; tex.y4 = yMin;
textureBuffer.push_back(tex);
}
[/code]

Share this post


Link to post
Share on other sites
Trienco    2555
A vertex is not just a position, it's the whole package of all its relevant attributes, texture coord, normal, color and whatever else is passed as generic attribute these days. Trying to share vertices is rather pointless for cubes unless you can find other ways to make it completely unique and still work for all faces.

Share this post


Link to post
Share on other sites
coderWalker    127
Thanks, I'm glad I can ask on here that way I didn't put all that work into it to only find out it's not possible.

So now how do I use just the Vertex Lists and not element lists?

Vertex:
1,1,1
1,2,1
2,2,1
2,1,1

Element:
0
1
2
3

Does anyone know any good VBO tutorials?

(I'm targeting OpenGL 3.1 )

Share this post


Link to post
Share on other sites
V-man    813
I don't know about the best, but if you want the worst, here you go
http://www.opengl.org/wiki/Vertex_Buffer_Object
http://www.opengl.org/wiki/VBO_-_more
http://www.opengl.org/wiki/VBO_-_just_examples (the one at the bottom for your GL 3.0)

and also
http://www.opengl.org/wiki/Tutorials

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By povilaslt2
      Hello. I'm Programmer who is in search of 2D game project who preferably uses OpenGL and C++. You can see my projects in GitHub. Project genre doesn't matter (except MMO's :D).
    • By ZeldaFan555
      Hello, My name is Matt. I am a programmer. I mostly use Java, but can use C++ and various other languages. I'm looking for someone to partner up with for random projects, preferably using OpenGL, though I'd be open to just about anything. If you're interested you can contact me on Skype or on here, thank you!
      Skype: Mangodoor408
    • By tyhender
      Hello, my name is Mark. I'm hobby programmer. 
      So recently,I thought that it's good idea to find people to create a full 3D engine. I'm looking for people experienced in scripting 3D shaders and implementing physics into engine(game)(we are going to use the React physics engine). 
      And,ye,no money =D I'm just looking for hobbyists that will be proud of their work. If engine(or game) will have financial succes,well,then maybe =D
      Sorry for late replies.
      I mostly give more information when people PM me,but this post is REALLY short,even for me =D
      So here's few more points:
      Engine will use openGL and SDL for graphics. It will use React3D physics library for physics simulation. Engine(most probably,atleast for the first part) won't have graphical fron-end,it will be a framework . I think final engine should be enough to set up an FPS in a couple of minutes. A bit about my self:
      I've been programming for 7 years total. I learned very slowly it as "secondary interesting thing" for like 3 years, but then began to script more seriously.  My primary language is C++,which we are going to use for the engine. Yes,I did 3D graphics with physics simulation before. No, my portfolio isn't very impressive. I'm working on that No,I wasn't employed officially. If anybody need to know more PM me. 
       
    • By Zaphyk
      I am developing my engine using the OpenGL 3.3 compatibility profile. It runs as expected on my NVIDIA card and on my Intel Card however when I tried it on an AMD setup it ran 3 times worse than on the other setups. Could this be a AMD driver thing or is this probably a problem with my OGL code? Could a different code standard create such bad performance?
    • By Kjell Andersson
      I'm trying to get some legacy OpenGL code to run with a shader pipeline,
      The legacy code uses glVertexPointer(), glColorPointer(), glNormalPointer() and glTexCoordPointer() to supply the vertex information.
      I know that it should be using setVertexAttribPointer() etc to clearly define the layout but that is not an option right now since the legacy code can't be modified to that extent.
      I've got a version 330 vertex shader to somewhat work:
      #version 330 uniform mat4 osg_ModelViewProjectionMatrix; uniform mat4 osg_ModelViewMatrix; layout(location = 0) in vec4 Vertex; layout(location = 2) in vec4 Normal; // Velocity layout(location = 3) in vec3 TexCoord; // TODO: is this the right layout location? out VertexData { vec4 color; vec3 velocity; float size; } VertexOut; void main(void) { vec4 p0 = Vertex; vec4 p1 = Vertex + vec4(Normal.x, Normal.y, Normal.z, 0.0f); vec3 velocity = (osg_ModelViewProjectionMatrix * p1 - osg_ModelViewProjectionMatrix * p0).xyz; VertexOut.velocity = velocity; VertexOut.size = TexCoord.y; gl_Position = osg_ModelViewMatrix * Vertex; } What works is the Vertex and Normal information that the legacy C++ OpenGL code seem to provide in layout location 0 and 2. This is fine.
      What I'm not getting to work is the TexCoord information that is supplied by a glTexCoordPointer() call in C++.
      Question:
      What layout location is the old standard pipeline using for glTexCoordPointer()? Or is this undefined?
       
      Side note: I'm trying to get an OpenSceneGraph 3.4.0 particle system to use custom vertex, geometry and fragment shaders for rendering the particles.
  • Popular Now