Improved OpenGL and X11 rotating cube examples.
This commit is contained in:
parent
e2420dfe76
commit
650e792350
2 changed files with 50 additions and 35 deletions
|
@ -36,6 +36,10 @@ void initialize(sf::Window& window)
|
|||
static const double pi = 3.141592654;
|
||||
GLdouble extent = std::tan(90.0 * pi / 360.0);
|
||||
glFrustum(-extent, extent, -extent, extent, 1.0, 500.0);
|
||||
|
||||
// Enable position and texture coordinates vertex components
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -62,46 +66,57 @@ void draw(sf::Window& window, float elapsedTime)
|
|||
glRotatef(elapsedTime * 6.f, 0.f, 1.f, 0.f);
|
||||
glRotatef(elapsedTime * 18.f, 0.f, 0.f, 1.f);
|
||||
|
||||
// Draw a cube
|
||||
glBegin(GL_QUADS);
|
||||
// Define a 3D cube (6 faces made of 2 triangles composed by 3 vertices)
|
||||
static const GLfloat cube[] =
|
||||
{
|
||||
// positions // colors
|
||||
-50, -50, -50, 1, 1, 0,
|
||||
-50, 50, -50, 1, 1, 0,
|
||||
-50, -50, 50, 1, 1, 0,
|
||||
-50, -50, 50, 1, 1, 0,
|
||||
-50, 50, -50, 1, 1, 0,
|
||||
-50, 50, 50, 1, 1, 0,
|
||||
|
||||
glColor3f(1.f, 1.f, 0.f);
|
||||
glVertex3f(-50.f, -50.f, -50.f);
|
||||
glVertex3f(-50.f, 50.f, -50.f);
|
||||
glVertex3f( 50.f, 50.f, -50.f);
|
||||
glVertex3f( 50.f, -50.f, -50.f);
|
||||
50, -50, -50, 1, 1, 0,
|
||||
50, 50, -50, 1, 1, 0,
|
||||
50, -50, 50, 1, 1, 0,
|
||||
50, -50, 50, 1, 1, 0,
|
||||
50, 50, -50, 1, 1, 0,
|
||||
50, 50, 50, 1, 1, 0,
|
||||
|
||||
glColor3f(1.f, 1.f, 0.f);
|
||||
glVertex3f(-50.f, -50.f, 50.f);
|
||||
glVertex3f(-50.f, 50.f, 50.f);
|
||||
glVertex3f( 50.f, 50.f, 50.f);
|
||||
glVertex3f( 50.f, -50.f, 50.f);
|
||||
-50, -50, -50, 1, 0, 1,
|
||||
50, -50, -50, 1, 0, 1,
|
||||
-50, -50, 50, 1, 0, 1,
|
||||
-50, -50, 50, 1, 0, 1,
|
||||
50, -50, -50, 1, 0, 1,
|
||||
50, -50, 50, 1, 0, 1,
|
||||
|
||||
glColor3f(0.f, 1.f, 1.f);
|
||||
glVertex3f(-50.f, -50.f, -50.f);
|
||||
glVertex3f(-50.f, 50.f, -50.f);
|
||||
glVertex3f(-50.f, 50.f, 50.f);
|
||||
glVertex3f(-50.f, -50.f, 50.f);
|
||||
-50, 50, -50, 1, 0, 1,
|
||||
50, 50, -50, 1, 0, 1,
|
||||
-50, 50, 50, 1, 0, 1,
|
||||
-50, 50, 50, 1, 0, 1,
|
||||
50, 50, -50, 1, 0, 1,
|
||||
50, 50, 50, 1, 0, 1,
|
||||
|
||||
glColor3f(0.f, 1.f, 1.f);
|
||||
glVertex3f(50.f, -50.f, -50.f);
|
||||
glVertex3f(50.f, 50.f, -50.f);
|
||||
glVertex3f(50.f, 50.f, 50.f);
|
||||
glVertex3f(50.f, -50.f, 50.f);
|
||||
-50, -50, -50, 0, 1, 1,
|
||||
50, -50, -50, 0, 1, 1,
|
||||
-50, 50, -50, 0, 1, 1,
|
||||
-50, 50, -50, 0, 1, 1,
|
||||
50, -50, -50, 0, 1, 1,
|
||||
50, 50, -50, 0, 1, 1,
|
||||
|
||||
glColor3f(1.f, 0.f, 1.f);
|
||||
glVertex3f(-50.f, -50.f, 50.f);
|
||||
glVertex3f(-50.f, -50.f, -50.f);
|
||||
glVertex3f( 50.f, -50.f, -50.f);
|
||||
glVertex3f( 50.f, -50.f, 50.f);
|
||||
-50, -50, 50, 0, 1, 1,
|
||||
50, -50, 50, 0, 1, 1,
|
||||
-50, 50, 50, 0, 1, 1,
|
||||
-50, 50, 50, 0, 1, 1,
|
||||
50, -50, 50, 0, 1, 1,
|
||||
50, 50, 50, 0, 1, 1
|
||||
};
|
||||
|
||||
glColor3f(1.f, 0.f, 1.f);
|
||||
glVertex3f(-50.f, 50.f, 50.f);
|
||||
glVertex3f(-50.f, 50.f, -50.f);
|
||||
glVertex3f( 50.f, 50.f, -50.f);
|
||||
glVertex3f( 50.f, 50.f, 50.f);
|
||||
|
||||
glEnd();
|
||||
// Draw the cube
|
||||
glVertexPointer(3, GL_FLOAT, 6 * sizeof(GLfloat), cube);
|
||||
glColorPointer(3, GL_FLOAT, 6 * sizeof(GLfloat), cube + 3);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue