Jump to content

  • Log In with Google      Sign In   
  • Create Account


Tallkotten

Member Since 28 Jun 2012
Offline Last Active May 29 2013 02:15 PM
-----

Posts I've Made

In Topic: Uncertainty with VBO and OpenGL

24 May 2013 - 02:10 AM

Ok, thanks!

 

I'm going to look at how some other people do it and ultimately decide on a way to go. But yours sound solid.


In Topic: Uncertainty with VBO and OpenGL

23 May 2013 - 02:03 PM

Ok, so you are saying: "Store a static VBO in the memory with some coordinates and texture data and then use glTranslate to move it on the screen"?


In Topic: Uncertainty with VBO and OpenGL

23 May 2013 - 02:46 AM

I might be talking in my sleep since i know very little on the VBO topic. This is my current code for drawing something to the screen:
 

    float texLeft = (float)clip.x / width;
    float texRight = (float)( clip.x + clip.w ) / width;
    float texTop = (float)clip.y / height;
    float texBottom = (float)( clip.y + clip.h ) / height;


    glPushMatrix();

        glTranslatef(0, 0, 0);

        glScalef(scale,scale,1);
        //set color
        glColor4f(R, G, B, A);

        glBegin( GL_QUADS );

            glTexCoord2f(  texLeft,    texTop );
            glVertex2f( x, y );

            glTexCoord2f( texRight,    texTop );
            glVertex2f( x+w, y );

            glTexCoord2f( texRight, texBottom );
            glVertex2f( x+w, y+h );

            glTexCoord2f(  texLeft, texBottom );
            glVertex2f( x, y+h );

        glEnd();

    glPopMatrix();

Each call i update the position and the texture-coords.

 

From the tutorials i've read on VBO's you have to do the same: (a straight copy-paste from the tutorials)

GLfloat vertices_position[8] = {
	x, y,
	x+w, y,
	x+w, y+h,
	x, y+h,
};

GLfloat texture_coord[8] = {
	texLeft, texTop,
	texRight, texTop,
	texRight, texBottom,
	texLeft, texBottom,
};

// Allocate space for vertex positions and texture coordinates
glBindBuffer(GL_ARRAY_BUFFER , vbo);
glBufferData(GL_ARRAY_BUFFER , sizeof(vertices_position) + sizeof(texture_coord), NULL, GL_STATIC_DRAW);

// Transfer the vertex positions:
glBufferSubData(GL_ARRAY_BUFFER , 0, sizeof(vertices_position), vertices_position);

// Transfer the texture coordinates:
glBufferSubData(GL_ARRAY_BUFFER , sizeof(vertices_position), sizeof(texture_coord), texture_coord);

This wouldn't in any way decrease the performance? If it will, how else do i define position and texture-coords when using a VBO?

 

Thank you for taking your time, i really appreciate it!


In Topic: Uncertainty with VBO and OpenGL

22 May 2013 - 02:32 PM

So you are suggesting that i check if the entity has changed location and if it has i'll update the vertices for location? And same goes with the texture. That's all i ever need to update, drawing location and texture-coords.

 

How much performance are we talking about? Lower than using immediate mode?


In Topic: Uncertainty with VBO and OpenGL

21 May 2013 - 10:35 AM

Here is how I use them.

When I load the game, I create a VBO for every type of object in the scene. For example, if there is a certian type of enemy in the game, then I create a single VBO for that enemy, load it in, then reuse the same VBO every time I draw an enemy of that type.

 

But each enemy hold it's own copy of it? Right?

 

VBO's are pretty much the same as your normal vertex buffers in OpenGL the only difference is that they are stored in GPU memory instead of System memory.

 

So you create a buffer object for each VB you want to have on the GPU and then you fill it with the vertex data for that object, because this stuff is now in GPU memory you want to avoid having to dynamically update these buffers each frame as that is a costly operation.

 

You should most definetly not create a new VBO each frame only create them once when you create the object that needs it.

 

I understanding right now is that i create a VBO when a (lets say) enemy is created. I then store this with the enemy until it's destroyed (how do i unload a VBO?).

 

You're saying that i should't update the data, is it ok to update the texture and vertex buffer? That shouldn't be a problem right? Because i need to be able to do that every frame.


PARTNERS