나는 간단한 OpenGL 프로그램을 가지고 있고 버텍스 셰이더에 저장된 인스턴스 배열을 그리려하고있다.OpenGL 인스턴스 배열 그리기
#version 330 core
uniform mat4 MVP;
const int VertexCount = 4;
const vec2 Position[VertexCount] = vec2[](
vec2(-100.0f, -100.0f),
vec2(-100.0f, 100.0f),
vec2(100.0f, -100.0f),
vec2(100.0f, 100.0f));
void main()
{
gl_Position = MVP * vec4(Position[gl_VertexID], 0.0, 1.0);
}
조각 쉐이더 :
버텍스 쉐이더 : 나는 렌더링이 다음과 쉐이더를 사용하고
#version 330 core
#define FRAG_COLOR 0
layout(location = FRAG_COLOR, index = 0) out vec4 Color;
void main()
{
Color = vec4(0, 1, 0, 1); //let it will be green.
}
내가 컴파일 내가 정점 배열 객체를 만들 쉐이더를 검증 한 후와 삼각형 스트립처럼 그립니다 :
glUseProgram(programHandle); //handle is checked and valid.
glBindVertexArray(vao);
glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, 1);
도면의 뷰포트는 t로 설정됩니다. 그는 glViewport (0, 0, 800, 600)와 같은 창 크기입니다. 매트릭스가 초기화
glUniformMatrix4fv(handle, 1, GL_FALSE, (GLfloat*)&matrix); //handle is checked and valid
:
Matrix::CreateOrthographicOffCenter(-200, 200, -200, 200, 1.0f, -1.0f, &matrix);
...
void Matrix::CreateOrthographicOffCenter(float left, float right, float bottom, float top, float zNearPlane, float zFarPlane, Matrix* matrix)
{
memset(matrix, 0, sizeof(Matrix));
matrix->M11 = 2.0f/(right - left);
matrix->M14 = (-right - left)/(right - left);
matrix->M22 = 2.0f/(top - bottom);
matrix->M24 = (-top - bottom)/(top - bottom);
matrix->M33 = 1.0f/(zFarPlane - zNearPlane);
matrix->M34 = (-zNearPlane)/(zFarPlane - zNearPlane);
matrix->M44 = 1.0f;
}
문제는 내 화면에는 삼각형 스트립을 가지고하지 않습니다 나는 노란 코드와 간단한 직교 행렬 MVP에 전달합니다. 나는 MVP 행렬없이 꼭지점을 그리려고했지만 (gl_Position = vec4 (Position [gl_VertexID], 0.0, 1.0)), 아무 것도 얻지 못했습니다. 문제가있는 곳을 찾는 방법?
'glDrawArrays'에서 (여전히 하나의 인스턴스 만 렌더링하기 때문에) 여전히 작동하지 않으면 인스턴스 문제가 아닙니다. –