Jump to content
  • Advertisement
Sign in to follow this  
bgoldbeck

OpenGL Translation Question.

This topic is 2660 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

I'm currently creating a GUI and I wonder if the way i'm using is not the most efficient way of going about drawing my Widgets on the screen. I am currently drawing them on the screen with a Display List that compiles the Widget :


glTexCoord2i(0, 0); glVertex3i(x + width, y , 0);
glTexCoord2i(1, 0); glVertex3i(x , y , 0);
glTexCoord2i(1, 1); glVertex3i(x , y + height, 0);
glTexCoord2i(0, 1); glVertex3i(x + width, y + height, 0);

As you can see i'm currently implementing the "X" and "Y" Position in the Quad itself. This works fine however, I find when I drag the Widget/Window around I have to recompile the Display List every time to update its position. That makes drawing the Widget a little slow, yet only while dragging.

My question is that I think it may be more effective to call a glTranslate with only using width and height vertices, but is this true?
I figure I could call it by
glTranslate to X, Y Then
glCallList()

Would this method be any faster or would the glTranslate function being repetitively called be slower.

Share this post


Link to post
Share on other sites
Advertisement
I don't recommend using glTranslate at all, because it has been deprecated since version 3.0 and removed since 3.1.
What you can do is use buffers like Vertex Buffer Objects for storing your vertex information and then use functions like glDrawElements to draw everything in the buffer at once.
It is much more modern and faster. If you are really into doing modern openGL stuff, you should also take a look at GLSL shaders.

Hope this helps you out ;)

Share this post


Link to post
Share on other sites

I don't recommend using glTranslate at all, because it has been deprecated since version 3.0 and removed since 3.1.
What you can do is use buffers like Vertex Buffer Objects for storing your vertex information and then use functions like glDrawElements to draw everything in the buffer at once.
It is much more modern and faster. If you are really into doing modern openGL stuff, you should also take a look at GLSL shaders.

Hope this helps you out ;)


Seeing glTranslate is being deprecated, you would still need to pass a similar matrix to the shader to render with and that is what the OP is intending to do. I agree with the fact that you should use VBO's for these things but very small VBO's have a bad impact on performance as well, so you might want to combine a few of these widgets into one larger buffer and specify which areas are used from the buffer in the draw call.

You could also define the width and height of the widget in to this matrix as the scale for the x and y axis. This would be better for your performance as the display list isn't changing it is the value for the transformation matrix that is changing.

Share this post


Link to post
Share on other sites

I don't recommend using glTranslate at all, because it has been deprecated since version 3.0 and removed since 3.1.
What you can do is use buffers like Vertex Buffer Objects for storing your vertex information and then use functions like glDrawElements to draw everything in the buffer at once.
It is much more modern and faster. If you are really into doing modern openGL stuff, you should also take a look at GLSL shaders.

Hope this helps you out ;)


Interesting, I did not know glTranslate was that way now. Its sort of seems annoying to me because a lot of the OpenGL stuff I have studied is outdated now days >: /
I will look into these "VBO" but, will they solve my issue with having to rebuild the objects buffer if an object moves its position in the scene?

I will take a better look into GLSL shaders, but from what I gather on Wikipedia it is like a library you add on to your program for additional functions. Is GLSL just something commonly used today by OpenGL users? or do you have a good example why its needed?


Thanks for your input btw : )

Share this post


Link to post
Share on other sites

[quote name='krienie' timestamp='1314875254' post='4856228']
I don't recommend using glTranslate at all, because it has been deprecated since version 3.0 and removed since 3.1.
What you can do is use buffers like Vertex Buffer Objects for storing your vertex information and then use functions like glDrawElements to draw everything in the buffer at once.
It is much more modern and faster. If you are really into doing modern openGL stuff, you should also take a look at GLSL shaders.

Hope this helps you out ;)


Interesting, I did not know glTranslate was that way now. Its sort of seems annoying to me because a lot of the OpenGL stuff I have studied is outdated now days >: /
I will look into these "VBO" but, will they solve my issue with having to rebuild the objects buffer if an object moves its position in the scene?

I will take a better look into GLSL shaders, but from what I gather on Wikipedia it is like a library you add on to your program for additional functions. Is GLSL just something commonly used today by OpenGL users? or do you have a good example why its needed?


Thanks for your input btw : )


[/quote]

Commonly today the fixed function pipeline is no longer used, it doesn't really matter if you use OpenGL or D3D, the programmable pipeline is the preferred way of controlling the GPU. GLSL, HLSL or CG is not really like a library it is actually a programming language that controls the GPU, so like normal source code it most be compiled and then executed on the GPU. Shaders programs define the transformation of vertices from application defined space to screen space (vertex shaders) and the shading of the pixels the object covers in the back buffer after transformation (pixel shader or fragment shader). Shaders allow you more freedom in what transformations and shading operations take place at runtime then the Fixed Function pipeline ever allowed. It is also really easy to write a shader that mimicks the normal Fixed Function pipeline, this is actually what the driver for a unified shader card does when you use fixed function API calls on such hardware.

The old diagrams of how data flows through the GPU still mostly hold true, whats changed is that certain blocks in that pipeline are now more controllable by the programmer.

The VBO won't fix your original question though a VBO is nothing more then a GPU memory area that holds your vertex data, you will still have to transform this. If you move your x and y position out of the VBO however and into a transformation matrix. All glTranslate and those functions alike did was modify the current ModelView matrix stack which was used to transform your vertices from model space into world space. This is now done by passing the transform matrices to the shader and writing the transformation code yourself.

Like I said before you might also want to include the width and height as a scaling matrix so that you just define a square in the VBO and the transformation matrices do the rest. This way you have to create and/or change the least amount of GPU resources.




PS: glVertex and the function like it define the immediate mode of OpenGL, immediate mode can hamper performance as current day GPU's (2003 and up) prefer to deal with batches instead of direct setup of vertices.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!