I need to Change  the GLfloat verts[]  and the GLushort Indices [] to create a 3D pyramid.  FreeGlut (Not Using This).  I am attaching the code  section I need help with and a picture of what the final should look like. If someone could help out I would appreciate it.   #include // cout, cerr #include // EXIT_FAILURE #include // GLEW library #include // GLFW library // GLM Math Header inclusions #include #include #include using namespace std; // Standard namespace /*Shader program Macro*/ #ifndef GLSL #define GLSL(Version, Source) "#version " #Version " core \n" #Source #endif // Unnamed namespace namespace { const char* const WINDOW_TITLE = "Tutorial 3.5"; // Macro for window title // Variables for window width and height const int WINDOW_WIDTH = 800; const int WINDOW_HEIGHT = 600; // Stores the GL data relative to a given mesh struct GLMesh { GLuint vao; // Handle for the vertex array object GLuint vbos[2]; // Handles for the vertex buffer objects GLuint nIndices; // Number of indices of the mesh }; // Main GLFW window GLFWwindow* gWindow = nullptr; // Triangle mesh data GLMesh gMesh; // Shader program GLuint gProgramId; } bool UInitialize(int, char*[], GLFWwindow** window); void UResizeWindow(GLFWwindow* window, int width, int height); void UProcessInput(GLFWwindow* window); void UCreateMesh(GLMesh &mesh); void UDestroyMesh(GLMesh &mesh); void URender(); bool UCreateShaderProgram(const char* vtxShaderSource, const char* fragShaderSource, GLuint &programId); void UDestroyShaderProgram(GLuint programId); //Global variables for the transform matrices uniform mat4 model; uniform mat4 view; uniform mat4 projection; void main() { gl_Position = projection * view * model * vec4(position, 1.0f); // transforms vertices to clip coordinates vertexColor = color; // references incoming color data } );/* Fragment Shader Source Code*/ const GLchar * fragmentShaderSource = GLSL(440, in vec4 vertexColor; // Variable to hold incoming color data from vertex shader out vec4 fragmentColor; void main() { fragmentColor = vec4(vertexColor); } );int main(int argc, char* argv[]) { if (!UInitialize(argc, argv, &gWindow)) return EXIT_FAILURE; // Sets the background color of the window to black (it will be implicitely used by glClear) glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // render loop // ----------- while (!glfwWindowShouldClose(gWindow)) { // input // ----- UProcessInput(gWindow); // Render this frame URender(); glfwPollEvents(); } // Release mesh data UDestroyMesh(gMesh); // Release shader program UDestroyShaderProgram(gProgramId); exit(EXIT_SUCCESS); // Terminates the program successfully } // Initialize GLFW, GLEW, and create a window bool UInitialize(int argc, char* argv[], GLFWwindow** window) { // GLFW: initialize and configure // ------------------------------ glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 4); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); #ifdef __APPLE__ glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); #endif // GLFW: window creation // --------------------- *window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE, NULL, NULL); if (*window == NULL) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return false; } glfwMakeContextCurrent(*window); glfwSetFramebufferSizeCallback(*window, UResizeWindow); // GLEW: initialize // ---------------- // Note: if using GLEW version 1.13 or earlier glewExperimental = GL_TRUE; GLenum GlewInitResult = glewInit(); if (GLEW_OK != GlewInitResult) { std::cerr << glewGetErrorString(GlewInitResult) << std::endl; return false; } // Clear the frame and z buffers glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Draws the triangles glDrawElements(GL_TRIANGLES, gMesh.nIndices, GL_UNSIGNED_SHORT, NULL); // Draws the triangle // Deactivate the Vertex Array Object glBindVertexArray(0); void 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;

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

I need to Change  the GLfloat verts[]  and the GLushort Indices []

to create a 3D pyramid.  FreeGlut (Not Using This).  I am attaching the code  section I need help with and a picture of what the final should look like. If someone could help out I would appreciate it.  

#include <iostream> // cout, cerr
#include <cstdlib> // EXIT_FAILURE
#include <GL/glew.h> // GLEW library
#include <GLFW/glfw3.h> // GLFW library

// GLM Math Header inclusions
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtc/type_ptr.hpp>

using namespace std; // Standard namespace

/*Shader program Macro*/
#ifndef GLSL
#define GLSL(Version, Source) "#version " #Version " core \n" #Source
#endif

// Unnamed namespace
namespace
{
const char* const WINDOW_TITLE = "Tutorial 3.5"; // Macro for window title

// Variables for window width and height
const int WINDOW_WIDTH = 800;
const int WINDOW_HEIGHT = 600;

// Stores the GL data relative to a given mesh
struct GLMesh
{
GLuint vao; // Handle for the vertex array object
GLuint vbos[2]; // Handles for the vertex buffer objects
GLuint nIndices; // Number of indices of the mesh
};

// Main GLFW window
GLFWwindow* gWindow = nullptr;
// Triangle mesh data
GLMesh gMesh;
// Shader program
GLuint gProgramId;
}


bool UInitialize(int, char*[], GLFWwindow** window);
void UResizeWindow(GLFWwindow* window, int width, int height);
void UProcessInput(GLFWwindow* window);
void UCreateMesh(GLMesh &mesh);
void UDestroyMesh(GLMesh &mesh);
void URender();
bool UCreateShaderProgram(const char* vtxShaderSource, const char* fragShaderSource, GLuint &programId);
void UDestroyShaderProgram(GLuint programId);

//Global variables for the transform matrices
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

void main()
{
gl_Position = projection * view * model * vec4(position, 1.0f); // transforms vertices to clip coordinates
vertexColor = color; // references incoming color data
}
);/* Fragment Shader Source Code*/
const GLchar * fragmentShaderSource = GLSL(440,
in vec4 vertexColor; // Variable to hold incoming color data from vertex shader

out vec4 fragmentColor;

void main()
{
fragmentColor = vec4(vertexColor);
}
);int main(int argc, char* argv[])
{
if (!UInitialize(argc, argv, &gWindow))
return EXIT_FAILURE;

// Sets the background color of the window to black (it will be implicitely used by glClear)
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

// render loop
// -----------
while (!glfwWindowShouldClose(gWindow))
{
// input
// -----
UProcessInput(gWindow);

// Render this frame
URender();

glfwPollEvents();
}

// Release mesh data
UDestroyMesh(gMesh);

// Release shader program
UDestroyShaderProgram(gProgramId);

exit(EXIT_SUCCESS); // Terminates the program successfully
}


// Initialize GLFW, GLEW, and create a window
bool UInitialize(int argc, char* argv[], GLFWwindow** window)
{
// GLFW: initialize and configure
// ------------------------------
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 4);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif

// GLFW: window creation
// ---------------------
*window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE, NULL, NULL);
if (*window == NULL)
{
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return false;
}
glfwMakeContextCurrent(*window);
glfwSetFramebufferSizeCallback(*window, UResizeWindow);

// GLEW: initialize
// ----------------
// Note: if using GLEW version 1.13 or earlier
glewExperimental = GL_TRUE;
GLenum GlewInitResult = glewInit();

if (GLEW_OK != GlewInitResult)
{
std::cerr << glewGetErrorString(GlewInitResult) << std::endl;
return false;
}

// Clear the frame and z buffers
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// Draws the triangles
glDrawElements(GL_TRIANGLES, gMesh.nIndices, GL_UNSIGNED_SHORT, NULL); // Draws the triangle

// Deactivate the Vertex Array Object
glBindVertexArray(0);

void 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;

 

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY