OpenGL 3.1

Started by
5 comments, last by V-man 12 years, 10 months ago
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:
Tutorial Series

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?


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:
clouds.png

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()
If this post was helpful please +1 or like it !

Webstrand
Advertisement
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.

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.


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.
f@dzhttp://festini.device-zero.de
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

Current method of Adding a face to buffer:

//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);
}
If this post was helpful please +1 or like it !

Webstrand
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.
f@dzhttp://festini.device-zero.de
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 )
If this post was helpful please +1 or like it !

Webstrand
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
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement