Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Maxjen

Member Since 07 Apr 2012
Offline Last Active Apr 04 2013 08:21 AM
-----

Posts I've Made

In Topic: Getting data from multiple vertex data

03 January 2013 - 11:09 AM

Bind a VBO and set a pointer, then bind another VBO and set another pointer. Yes, the second binding will unbind the first one, but a vertex attribute pointer depends on the VBO binding when the pointer is set, not when the arrays are drawn.

Thank you very much, that is all I needed to know!

There is perhaps still a misunderstanding. The vertex positions are the same for the faces, edges, and point handles. You need only 1 VBO with the position, and that is the VBO I've mentioned as "shared". However, you need to transport the edge color as well, and that attribute is unique to edge rendering. Hence create another VBO for the edge color (but notice that it is still given for each vertex; but that isn't a problem with your kind of coloring the edges).

There is no misunderstanding but thanks! What you described is exactly how I was going to do it. There was only the technical problem of how to use more than one vertex buffer.rolleyes.gif


In Topic: Getting data from multiple vertex data

03 January 2013 - 07:51 AM

No help? Basically I only want to do what was already suggested I just don't know exactly how to do it in openGL.

 

For sure, a clean way under the condition of not replicating data would be to use 3 VBOs (1 with the data shared between face and line drawing, 1 with the data used for face drawing only, and 1 with the data used for line drawing only), and 2 IBOs (1 for face drawing and 1 for line drawing).

 

I want 2 VBOs but how? If I bind one buffer and then the next will the first buffer not be unbound? Or is it enough to bind the buffer, set the vertex attrib pointers and then unbind it again before the draw call?


In Topic: Getting data from multiple vertex data

30 December 2012 - 01:26 PM

Wow, so many replies! Thanks!

 

To clarify what I want to do: The Triangle class will be used only for the ground. For other type of objects I will make seperate classes. And I want to perform the most basic actions on the vertices like move, rotate, scale.(like in blender) This is inspired by the game soldat. This is an example of a map in soldat.

 

How the drawing is done: In two passes. Somewhere in my main loop I call triangles->draw() and later selection->draw(). The Triangle class manages the vertex buffer for the triangles. It has functions to add/remove triangles and if the buffer is full it automatically creates a new buffer with twice the size and copies the data. The buffer has this structure:

 


struct Vertex {
    float x, y;      // position
    float u, v;      // texturecoords
    char r, g, b, a; // color
};

The Triangle class also has the index buffer for drawing the triangles.

This is the draw function for the triangles:

 

void Triangles::draw() {
    glUseProgram(shaderProgram);

    glBindBuffer(GL_ARRAY_BUFFER, vertexBufferId);
    // vertex
    glVertexAttribPointer(vertexPositionLocation, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
    // texCoord
    glVertexAttribPointer(texCoordLocation, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)(2 * sizeof(float)));
    // color
    glVertexAttribPointer(vertexColorLocation, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex), (GLvoid*)(4 * sizeof(float)));
    glEnableVertexAttribArray(vertexPositionLocation);
    glEnableVertexAttribArray(texCoordLocation);
    glEnableVertexAttribArray(vertexColorLocation);
	
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferId);

    glEnable(GL_TEXTURE_2D);
    for(int i = 0; i < triangleCount; ++i) {
        if(trianglesData[i].isUsed) {
            glBindTexture(GL_TEXTURE_2D, trianglesData[i].texture->id);
            glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, (GLvoid*)(sizeof(Triangle)*i));
        }
    }
    glDisable(GL_TEXTURE_2D);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

    glDisableVertexAttribArray(vertexColorLocation);
    glDisableVertexAttribArray(texCoordLocation);
    glDisableVertexAttribArray(vertexPositionLocation);

    glBindBuffer(GL_ARRAY_BUFFER, 0);

    glUseProgram(0);
}

 

I will also replace the for loop in the future and instead use the spatial tree from Box2D to draw only currently visible triangles.

 

Now the problem is the draw method of the selection class. Currently I already render white points for the vertices and I reuse the vertex buffer from the Triangle class with a new index buffer. I want to do the same for the edges, however I need additional information. For every edge where at least one vertex is selected I need two booleans to know how to draw the line. e.g. if only one vertex is selected then the line should fade from full white to transparent. I think this information doesn't belong into the Triangle class because I might e.g. use the Triangle class later in the game itself where I don't need selections. So instead I want to create a new buffer with the booleans. What I don't know is how to use them both at once. e.g. can I even do something like this:

 


glBindBuffer(GL_ARRAY_BUFFER, triangleVertexBufferId);
glVertexAttribPointer(vertexPositionLocation, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0); 
glBindBuffer(GL_ARRAY_BUFFER, selectionVertexBufferId);
glVertexAttribPointer(vertexSelectionLocation, 2, GL_FLOAT, GL_FALSE, sizeof(Selection), 0);
...
glDrawElements(GL_LINES, ...);

Wouldn't the result be that only the second buffer is bound when I draw the lines? But I need both.

 


In Topic: Am i learning too slow?

14 April 2012 - 06:31 AM

Just an idea: You could try to integrate external libraries like box2d. That's what I'm doing right now as my first real project. Here's a flash example of what's possible with box2d. I use SDL and openGL to draw the objects that are simulated by box2d but you could probably also use SFML if you want. For me it was a very satisfying moment when I first successfully ran my program which had a physically simulated box. This could be a goal while learning SDL, SFML or something. Basically all you need to know is c++ and how to draw images with arbitrary rotation.

In Topic: Program using too many resources

07 April 2012 - 11:22 AM

Thanks for the replies.

But try putting a Sleep(millisecondshere); in the loop. It stops executing the program for a small time, so if theres nothing to compute you can make it sleep for a while. You probably need to include windows.h or some other header.
...
You would probably use it by timing your loop iteration, and if theres still time until the start of the next time step, sleep for a while.

Is this the same thing as capping the framerate? I might actually do that. In fact I just found out that the game I was comparing it with (braid) also caps the framerate at 30. I'll try to find out how to do this sleep thing on linux.

I'm still wondering though if there is anything else I might be doing wrong? Because I feel that even games like ut2004 where I have over 100 frames per second don't create as much noise as mine.(although that's maybe operating system related as that was on windows or my feeling is deceiving me)

Also are you sure its the processor fan and not the GPU fan?

It might be the GPU fan, I have no idea.

Antheus:
It is true that I have a poor hardware build. My laptop is noisy with every game I play. I was just wondering because with my program it is especially noisy.

PARTNERS