As a follow-up to Denis's answer...
If you are willing to learn a bit more OpenGL (perhaps a tall order if you just want to draw a cube...) here is the code that I reuse when doing small demos. It uses vertex array+buffer objects and creates a textured rectangular prism centered at (0, 0, 0). You'll need to provide your own texture.
The code to generate the rectangular prism is:
void GLmakeRect(GLuint vao, GLuint vbo[2], float w, float h, float d, GLuint storageHint) {
/*
8|---|9
0|BAC|1
10|---|---|---|12
|LEF|TOP|RIG|
11|---|---|---|13
3|FRO|2
4|---|5
|BOT|
6|---|7
*/
float verts[] = {
-0.5*w, 0.5*h, -0.5*d, 1.0/3.0, 0.25,
0.5*w, 0.5*h, -0.5*d, 2.0/3.0, 0.25,
0.5*w, 0.5*h, 0.5*d, 2.0/3.0, 0.5,
-0.5*w, 0.5*h, 0.5*d, 1.0/3.0, 0.5,
-0.5*w, -0.5*h, 0.5*d, 1.0/3.0, 0.75,
0.5*w, -0.5*h, 0.5*d, 2.0/3.0, 0.75,
-0.5*w, -0.5*h, -0.5*d, 1.0/3.0, 1.0,
0.5*w, -0.5*h, -0.5*d, 2.0/3.0, 1.0,
-0.5*w, -0.5*h, -0.5*d, 1.0/3.0, 0.0,
0.5*w, -0.5*h, -0.5*d, 2.0/3.0, 0.0,
-0.5*w, -0.5*h, -0.5*d, 0.0, 0.25,
-0.5*w, -0.5*h, 0.5*d, 0.0, 0.5,
0.5*w, -0.5*h, -0.5*d, 1.0, 0.25,
0.5*w, -0.5*h, 0.5*d, 1.0, 0.5
};
int polys[] = {
0, 3, 1, 1, 3, 2, // TOP
3, 4, 2, 2, 4, 5, // FRONT
4, 6, 5, 5, 6, 7, // BOTTOM
8, 0, 9, 9, 0, 1, // BACK
10, 11, 0, 0, 11, 3, // LEFT
1, 2, 12, 12, 2, 13 // RIGHT
};
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), &verts[0], storageHint);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5*sizeof(float), 0);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5*sizeof(float), (void*)(3*sizeof(float)));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo[1]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(polys), &polys[0], storageHint);
}
You can call the function like this during initialization:
GLuint vao, vbo[2]
glGenVertexArrays(1, &vao);
glGenBuffers(2, &vbo[0]);
GLmakeRect(vao, vbo, 1, 1, 1, GL_STATIC_DRAW);
To draw the cube in your render loop, do:
glBindTexture(GL_TEXTURE_2D, yourTextureHandleHere);
glBindVertexArray(vao);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);