오늘 제가 튜토리얼을 따르려고했는데 http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/에서 튜토리얼을 거의 따라 왔지만 같은 결과를 얻지 못했습니다. 기본 작업을 처리하는 데 도움이되는 몇 가지 클래스를 사용했습니다. 그러나 이전에 사용했기 때문에 잘못하지 않았습니다.OpenGL에서 행렬 사용 - MVP 행렬이 작동하지 않습니다.
현재 결과는 아무 것도 없습니다. 나는 삼각형을 어디에도 볼 수 없습니다. 버텍스 쉐이더의 MVP * 부분을 제거하면 작동합니다.
많은 코드가 튜토리얼에서 복사되고 붙여 넣어집니다. 1. 잘못된 설정이 (내가 다운로드 튜토리얼의 소스 코드를 컴파일.) 2. 나쁜 초기화 코드를 (밖으로 MVP를 취할 경우 * 버텍스 쉐이더 중 일부는 작동 :
문제 난 배제했습니다 괜찮음)
내가 도와 줄 수있는 모든 도움에 감사드립니다.
버텍스 쉐이더 (Basic.vertexshader) :
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(pro);
glUniformMatrix4fv(MVPID, 1, GL_FALSE, &MVP[0][0]);
// bind location
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 3, (void*)0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
: 여기
#version 400 core
layout(location = 0) in vec3 location;
uniform mat4 MVP;
void main()
{
gl_Position = MVP * vec4(location,1);
// gl_Position = vec4(location, 1); *** this works fine, without the transformations
//coord = texCoord;
}
는 (한 번만 호출) 초기화 코드
glClearColor(0.2f, 0.2f, 0.2f, 1.f);
glGenVertexArrays(1, &vaoID);
glBindVertexArray(vaoID);
// load program
pro = LoadShaders("Basic.vertexshader", "Basic.fragmentshader");
MVPID = glGetUniformLocation(pro, "MVP");
// Projection matrix : 45° Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units
Projection = glm::perspective(45.0f, 4.f/3.f, 0.1f, 100.f);
// Or, for an ortho camera :
//glm::mat4 Projection = glm::ortho(-10.0f,10.0f,-10.0f,10.0f,0.0f,100.0f); // In world coordinates
// Camera matrix
View = glm::lookAt(
glm::vec3(4, 3, 0), // Camera is at (4,3,3), in World Space
glm::vec3(0, 0, 0), // and looks at the origin
glm::vec3(0, 1, 0) // Head is up (set to 0,-1,0 to look upside-down)
);
// Model matrix : an identity matrix (model will be at the origin)
Model = glm::mat4(1.0f);
// Our ModelViewProjection : multiplication of our 3 matrices
// Our ModelViewProjection : multiplication of our 3 matrices
MVP = Projection * View * Model; // Remember, matrix multiplication is the other way around
GLfloat verts[] =
{// ---LOCATION----
-1.f, -1.f, 0.f,
1.f, -1.f, 0.f,
0.f, 1.f, 0.f,
};
// init vbo
glGenBuffers(1, &vboID);
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);
return 0;
그리고 마지막으로 무승부 코드 (모든 프레임)입니다
내가 놓친 몇 가지 중요한 코드가있는 경우 전체 소스 코드를 여기에서 다운로드 할 수 있습니다.
https://www.dropbox.com/sh/zb3r85rj7lgfzs2/AADh0nJSVw5dO2fUAJdrnrTua?dl=0
편집 : 그것은 중요한 경우, 내가 연결있어 lib 디렉토리 파일이 glfw3.lib, opengl32.lib 있습니다 glew32.lib 비주얼 스튜디오 2013 컴파일러 을 사용하고
아, 그게 의미가있어, tommorow. 감사! –