저는 나무 딸기 파이에 대한 몇 가지 기본 OpenGL을 배우려고합니다. 나는 내가 해결할 수없는 prbolem에 충돌 https://solarianprogrammer.com/2013/05/13/opengl-101-drawing-primitives/ http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-9-vbo-indexing/라스베리 파이, 인덱스 된 버텍스에 대한 OpenGL
이 자습서를 folow. 배열에서 꼭지점을 나열하여 삼각형을 그려야 만 성공적으로 만들었지 만 동일한 작업을 시도했지만 인덱스를 사용하면 작동하지 않고 그 이유를 알 수 없습니다. 그것은 성공적으로 컴파일되고 실행되지만 삼각형은 표시되지 않습니다.
두 자습서는 버퍼를 추가하고 "glDrawArrays"를 "glDrawElements"로 바꿉니다. 하지만 뭔가를 놓쳐 버렸음에 틀림 없습니다.
#include <stdio.h>
#include <unistd.h>
#include "../common/startScreen.h"
#include "../common/LoadShaders.h"
// Include GLM
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
using namespace glm;
int main(int argc, const char **argv)
{
float r=0.0;
InitGraphics();
printf("Screen started\n");
// Create and compile our GLSL program from the shaders
GLuint programID = LoadShaders("simpletransformvertshader.glsl", "simplefragshader.glsl");
printf("Shaders loaded\n");
// Get a handle for our "MVP" uniform
GLuint MatrixID = glGetUniformLocation(programID, "MVP");
// Get a handle for our buffers
GLuint vertexPosition_modelspaceID = glGetAttribLocation(programID, "vertexPosition_modelspace");
// Projection matrix
glm::mat4 Projection = glm::perspective(45.0f, 16.0f/9.0f, 0.1f, 100.0f);
// Camera matrix
glm::mat4 View = glm::lookAt(
glm::vec3(0,0,5),
glm::vec3(0,0,0),
glm::vec3(0,1,0),
);
//glm::mat4 myMatrix = glm::translate(10.0f, 0.0f, 0.0f);
// Model matrix : an identity matrix (model will be at the origin)
glm::mat4 Model = glm::mat4(1.0f);
// Our ModelViewProjection : multiplication of our 3 matrices
glm::mat4 MVP = Projection * View * Model; // Remember, matrix$
//glm:mat4 MVP = Prpkection * View * Model;
GLfloat g_vertex_buffer_data[] = {
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
1.0f, 1.0f, 0.0f,
// -1.0, 1.0f, 0.0f,
};
GLuint indices[3] = {
0,1,2,
// 2,3,0
};
// Set the viewport
GLuint vertexbuffer;
glGenBuffers(1, &vertexbuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_bu$
GLuint eab;
glGenBuffers(1, &eab);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, eab);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STAT$
do{
// Model = glm::rotate(Model, r, glm::vec3(0.0f, 0.0f, 1.0f));
glClear(GL_COLOR_BUFFER_BIT);
// Use our shader
glUseProgram(programID);
// Send our transformation to the currently bound shader,
// in the "MVP" uniform
glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);
// 1rst attribute buffer : vertices
glEnableVertexAttribArray(vertexPosition_modelspaceID);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glVertexAttribPointer(
vertexPosition_modelspaceID,
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
// see above glEnableVertexAttribArray(vertexPosition_modelspaceID);
// Draw the triangle !
// glDrawArrays(GL_TRIANGLES, 0, 3);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, eab);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, 0);
glDisableVertexAttribArray(vertexPosition_modelspaceID);
updateScreen();
}
while(1);
// Cleanup VBO
glDeleteBuffers(1, &vertexbuffer);
glDeleteBuffers(1, &eab);
glDeleteProgram(programID);
}
감사합니다. 문제가 해결되었습니다! 튜토리얼의 예제와 함께 제공된 Makefile을 사용하고있었습니다. 나는 괜찮을 거라고 생각했다. 컴파일 설정을 살펴 봐야 할 것 같습니다. – Barricadexx
GLEW를 사용하여 런타임에 사용 가능한 기능/확장을 확인하는 것이 좋습니다. – WhoCares