Convert Quaternion rotation to rotation matrix?

The following code is based on a quaternion (qw, qx, qy, qz), where the order is based on the Boost quaternions: boost::math::quaternion<float> quaternion; float qw = quaternion.R_component_1(); float qx = quaternion.R_component_2(); float qy = quaternion.R_component_3(); float qz = quaternion.R_component_4(); First you have to normalize the quaternion: const float n = 1.0f/sqrt(qx*qx+qy*qy+qz*qz+qw*qw); qx *= n; qy … Read more

how to enable vertical sync in opengl?

On Windows there is OpenGL extension method wglSwapIntervalEXT. From the post by b2b3 If you are working on Windows you have to use extensions to use wglSwapIntervalExt function. It is defined in wglext.h. You will also want to download glext.h file. In wglext file all entry points for Windows specific extensions are declared. All … Read more

glVertexAttribPointer clarification

Some of the terminology is a bit off: A Vertex Array is just an array (typically a float[]) that contains vertex data. It doesn’t need to be bound to anything. Not to be confused with a Vertex Array Object or VAO, which I will go over later A Buffer Object, commonly referred to as a … Read more

OpenGL stretched shapes – aspect ratio

glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); float aspect = (float)width / (float)height; glOrtho(-aspect, aspect, -1, 1, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); Update: Explanation what happens OpenGL is a state machine and in the case of OpenGL-2.1 and below maintains a set of transformation matrices. A vertex ↑v first gets multiplied with the modelview matrix to yield a … Read more

GLSL, semaphores?

Basically, you’re just implementing a spinlock. Only instead of one lock variable, you have an entire texture’s worth of locks. Logically, what you’re doing makes sense. But as far as OpenGL is concerned, this won’t actually work. See, the OpenGL shader execution model states that invocations execute in an order which is largely undefined relative … Read more

Is it possible to rotate an object around its own axis and not around the base coordinate’s axis?

First thing you should know is that in OpenGL, transformation matrices are multiplied from right. What does it mean? It means that the last transformation you write gets applied to the object first. So let’s look at your code: gl.glScalef(0.8f, 0.8f, 0.8f); gl.glTranslatef(0.0f, 0.0f, -z); gl.glRotatef(xrot, 1.0f, 0.0f, 0.0f); //X gl.glRotatef(yrot, 0.0f, 1.0f, 0.0f); //Y … Read more