//the cube to save eight points to an array in
static const GLfloat vertex_list [] [3] = {
0.5 f, 0.5 f, 0.5 f,
0.5 f, 0.5 f, 0.5 f,
//…
};
glBegin(GL_LINE_STRIP);
glBegin(GL_LINE_STRIP);
glVertex3fv (vertex_list [0]).
glVertex3fv (vertex_list [2]).
glVertex3fv (vertex_list [3]).
glVertex3fv (vertex_list [1]).
//…
glEnd();
changes, although the code to get longer, but it is easy to read. It’s easy to see that the four vertices 0, 2, 3, and 1 form a square.
a little observation can be found, we use a lot of glVertex3fv function, each one is only one of the vertex sequence number is different, so we can define an array of serial number, put all the serial number is in. This makes the code much simpler.
//cube will save eight points to an array of
static const GLfloat vertex_list [] [3] = {
0.5 f, 0.5 f, 0.5 f,
0.5 f to 0.5 f, 0.5 f, f
– 0.5, 0.5 f to 0.5 f,
0.5 f, 0.5 f, 0.5 f,
– 0.5 f to 0.5 f, 0.5 f,
0.5 f to 0.5 f, 0.5 f,
0.5 f, f 0.5, 0.5 f,
0.5 f, f 0.5, 0.5 f,
};
static const GLint index_list[][4] = {
static const GLint index_list[][4] = {
static const GLint index_list[]
0, 2, 3, 1,
0, 4, 6, 2,
0, 1, 5, 4,
4, 6, 7, 5,
1, 3, 7, 3,
2, 6, 7, 7,};
int i, j;
glBegin(GL_LINE_STRIP)
glBegin(GL_LINE_STRIP)
glBegin(GL_LINE_STRIP);
for(i=0; i< 6;
for(j=0; j=0; j=0; j< 4. + + j)// each side has four vertices, cycle four times
glVertex3fv (vertex_list [index_list [I] [j]]).
glEnd();
This gives us a more mature version of how to draw a cube. The data and code are basically separate. All the vertices are put in one array, and the number of the vertices is put in another array, and the code to draw the cube from these two arrays is very simple.
faces counter clockwise, faces away from us clockwise, we have the index_list array above.
Read More:
- Drawing a cube with OpenGL
- An example of drawing rotating cube with OpenGL
- Implementation of OpenGL rotating cube
- OpenGL cube texture map
- Drawing function of GLUT
- Stm32cube ide installation – NSIS error problem
- ERROR command failed: npm install –loglevel error vue-cli-plugin-cube-ui -D
- Anaconda Matplotlib drawing Chinese garbled solution
- Opencv453 drawing rectangle function error reporting solution
- Rstudio drawing problem
- OpenGL learning — problems encountered in compiling OpenGL program for the first time
- Ggplot2 drawing calls external variables
- Free dynamic screen capture drawing tool under MAC: KAP
- “Typeerror: invalid dimensions for image data” in Matplotlib drawing imshow() function
- An example of 3D data modeling based on VB6 + OpenGL
- How to use C # to get image format without system. Drawing. Common
- OpenGL basic graphics programming – OpenGL and 3D graphics world
- Graphviz. Backend. Executablenotfound: failed to execute ‘dot’ Python uses graphviz to solve drawing errors
- OpenGL learning summary (1)
- 2016.11.1 OpenGL learning, black screen does not display graphics