define element indices GLubyte indices 0 1 2 2 3 4 GLuint VBO EBO

Define element indices glubyte indices 0 1 2 2 3 4

This preview shows page 2 - 4 out of 4 pages.

// define element indicesGLubyte indices[] = {0, 1, 2,2, 3, 4};GLuint VBO, EBO;__glewGenBuffers(1, &VBO); // create VBO__glewGenBuffers(1, &EBO); // create EBO__glewBindBuffer(GL_ARRAY_BUFFER, VBO); // activate the buffer and select VBO
Background image
__glewBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); // activate the buffer and select EBO__glewBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); // Load vertex attributes__glewBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); // Load indices attributes// specify attributes location and layout to GPU__glewVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GL_FLOAT), (GLvoid*)0);__glewEnableVertexAttribArray(0);// specify attributes location and layout to gpu__glewVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GL_FLOAT), (GLvoid*)(3 * sizeof(GL_FLOAT)));__glewEnableVertexAttribArray(1);// Vertex Shader source codestring vertexShaderSource ="#version 330 core\n""layout(location = 0) in vec4 vPosition;\n""layout(location = 1) in vec4 aColor;\n""out vec4 oColor;""void main()\n""{\n""gl_Position = vPosition""oColor = aColor;""}\n";// Fragment Shader source codestring fragmentShaderSource ="#version 330 core\n""in vec4 oColor;""out vec4 fragColor;\n""void main()\n""{\n""fragColor = oColor;""}\n";// Create shader programGLuint shaderProgram = CreateShaderProgram(vertexShaderSource, fragmentShaderSource);// use shader program exe__glewUseProgram(shaderProgram);/* Loop until the user closes the window */while (!glfwWindowShouldClose(window)){// Resize window and graphics simultaneouslyglfwGetFramebufferSize(window, &width, &height);glViewport(0, 0, width, height);/* Render here */glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// draw primitivedraw();
Background image
/* Swap front and back buffers */glfwSwapBuffers(window);/* Poll for and process events */glfwPollEvents();}glfwTerminate();return 0;}
Background image

You've reached the end of your free preview.

Want to read all 4 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture