Page 1 of 1

HOW TO MAKE MY CUBE INTO A RECTANGULAR CUBE & LAY IT DOWN ON THE PLANE?? CODE (USING GLEW): // Implements the UCreateMes

Posted: Thu Jul 14, 2022 2:19 pm
by answerhappygod
HOW TO MAKE MY CUBE INTO A RECTANGULAR CUBE & LAY ITDOWN ON THE PLANE??
How To Make My Cube Into A Rectangular Cube Lay It Down On The Plane Code Using Glew Implements The Ucreatemes 1
How To Make My Cube Into A Rectangular Cube Lay It Down On The Plane Code Using Glew Implements The Ucreatemes 1 (244.49 KiB) Viewed 26 times
CODE (USING GLEW):
// Implements the UCreateMesh functionvoid UCreateMesh(GLMesh& mesh){ // Position and Color data GLfloat verts[] = { // Vertex Positions //Colors (r,g,b,a) 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, // Top Right Vertex 0 0.5f, -0.5f, 0.0f, 0.0f,1.0f, 0.0f, 1.0f, // Bottom Right Vertex 1 -0.5f, -0.5f, 0.0f, 0.0f, 0.0f,1.0f, 1.0f, // Bottom Left Vertex 2 -0.5f, 0.5f, 0.0f, 1.0f,0.0f, 1.0f, 1.0f, // Top Left Vertex 3
0.5f, -0.5f, -1.0f, 0.5f, 0.5f, 1.0f, 1.0f, // 4 br right 0.5f, 0.5f, -1.0f, 1.0f, 1.0f, 0.5f, 1.0f, // 5 tl right -0.5f, 0.5f, -1.0f, 0.2f,0.2f, 0.5f, 1.0f, // 6 tl top -0.5f, -0.5f, -1.0f, 1.0f, 0.0f,1.0f, 1.0f // 7 bl back };
// Index data to share position data GLushort indices[] = { 0, 1, 3, // Triangle 1 1, 2, 3, // Triangle 2 0, 1, 4, // Triangle 3 0, 4, 5, // Triangle 4 0, 5, 6, // Triangle 5 0, 3, 6, // Triangle 6 4, 5, 6, // Triangle 7 4, 6, 7, // Triangle 8 2, 3, 6, // Triangle 9 2, 6, 7, // Triangle 10 1, 4, 7, // Triangle 11 1, 2, 7 // Triangle 12 };
const GLuint floatsPerVertex = 3; const GLuint floatsPerColor = 4;
glGenVertexArrays(1, &mesh.vao); // wecan also generate multiple VAOs or buffers at the same time glBindVertexArray(mesh.vao);
// Create 2 buffers: first one for thevertex data; second one for the indices glGenBuffers(2, mesh.vbos); glBindBuffer(GL_ARRAY_BUFFER, mesh.vbos[0]); //Activates the buffer glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts,GL_STATIC_DRAW); // Sends vertex or coordinate data to theGPU
mesh.nIndices = sizeof(indices) /sizeof(indices[0]); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,mesh.vbos[1]); glBufferData(GL_ELEMENT_ARRAY_BUFFER,sizeof(indices), indices, GL_STATIC_DRAW);
// Strides between vertex coordinates is 6(x, y, z, r, g, b, a). A tightly packed stride is 0. GLint stride = sizeof(float) * (floatsPerVertex +floatsPerColor);// The number of floats before each
// Create Vertex Attribute Pointers glVertexAttribPointer(0, floatsPerVertex, GL_FLOAT,GL_FALSE, stride, 0); glEnableVertexAttribArray(0);
glVertexAttribPointer(1, floatsPerColor,GL_FLOAT, GL_FALSE, stride, (char*)(sizeof(float) *floatsPerVertex)); glEnableVertexAttribArray(1);}
How To Make My Cube Into A Rectangular Cube Lay It Down On The Plane Code Using Glew Implements The Ucreatemes 2
How To Make My Cube Into A Rectangular Cube Lay It Down On The Plane Code Using Glew Implements The Ucreatemes 2 (223.76 KiB) Viewed 26 times