PDA

View Full Version : how to paint, translate and scale a cube



andrea84
06-25-2010, 02:14 AM
Hello everybody I'm working with a program written in C and I need. now I've used the function glutsolidcube which draws a cube centered in the point (0,0,0). I need to translate this cube and to scale it. How can I do that?
thank you all

kowal
06-25-2010, 05:50 AM
You can use matrices to do that.
OpenGL has bulit-in matrix stack and couple of functions to manipulate it, but they are deprecated for now.
(It's still good idea to learn some deprecated stuff, it will give You understanding of basic rendering pipeline)
read some tutorials:
nehe(outdated, but still useful): http://nehe.gamedev.net/

Alfonse Reiheart started writing some up to date tutorials,
(they are not finished Yet, but basics like rotations and translations should be complete):
http://www.arcsynthesis.org/gltut/

andrea84
06-25-2010, 11:53 PM
I need an example, I don't have to study openGL but I just need it to build, to traslate and to scale a cube in another project.
thank you all

maedhros777
06-26-2010, 05:15 AM
The functions you would need would be glTranslatef (http://www.opengl.org/sdk/docs/man/xhtml/glTranslate.xml) and glScalef (http://www.opengl.org/sdk/docs/man/xhtml/glScale.xml). However, understanding how these work would be beneficial to your understanding of how OpenGL works. I'm not quite sure why you don't need to know about OpenGL if you're currently writing a program in it, but if you're determined, then you can just use those 2 functions.

Oh yeah, kowal: Out of curiosity, which functions are deprecated? And which functions have replaced them?

kowal
06-26-2010, 10:46 AM
Oh yeah, kowal: Out of curiosity, which functions are deprecated? And which functions have replaced them?

In OpenGL 3.0+ all fixed-pipeline stuff is deprecated.
This includes glTranslatef, glScalef, glRotatef, etc. The whole matrix stack, and many more (read the spec)

They are still available in compatibility profile, but if You wish to stay in core,
You should write your own matrix-manipulation routines, (or use third-party lib) and pass matrices as attributes to shaders.

maedhros777
06-27-2010, 05:05 AM
Wait, but if you write your own matrix-manipulation routines, then isn't that slower (less hardware support)? Or is glMultMatrix() not deprecated?

ZbuffeR
06-27-2010, 12:10 PM
glMultMatrix is deprecated. Even before, it was done on the CPU by the driver.

maedhros777
06-27-2010, 02:34 PM
Hm, interesting, I didn't know that. I'll switch to my own matrix functions now -- although I checked the spec and just about all the OpenGL code I use is deprecated :D

As a side note though, if matrix calculations are done outside of OpenGL, then should they be loaded in with glLoadMatrix(), or should all the vertices rendered be manually modified by the modelview and projection matrices?

kowal
06-27-2010, 02:47 PM
Your matrices should be loaded as attributes (or uniforms, it depends) into the vertex shader.
In vertex shader You transform vertex position by projection and modelviev matrices.

In OpenGL 2.1 shaders (I do not remember GLSL version) there was special function to do this: ftransform (now also deprecated)
(matrices loaded by OpenGL matrix stack)