간단한 삼각형 렌더링에 문제가 있습니다. 삼각형이 없다는 것을 제외하고는 아래의 코드가 컴파일되어 실행됩니다. 검정색 배경. 당신이 쉐이더를 가지고 있지 않기 때문에삼각형이 렌더링되지 않습니다.
GLuint VBO;
static void RenderSceneCB()
{
//glClear sets the bitplane area of the window to values previously selected by glClearColor, glClearDepth, and glClearStencil.
glClear(GL_COLOR_BUFFER_BIT);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
//swaps the buffers of the current window if double buffered.
glutSwapBuffers();
}
static void InitializeGlutCallbacks()
{
glutDisplayFunc(RenderSceneCB);
}
static void CreateVertexBuffer()
{
Vector3f Vertices[3];
Vertices[0] = Vector3f(-1.0f, -1.0f, 0.0f);
Vertices[1] = Vector3f(1.0f, -1.0f, 0.0f);
Vertices[2] = Vector3f(0.0f, 1.0f, 0.0f);
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
glutInitWindowSize(1024, 768);
glutInitWindowPosition(100, 100);
glutCreateWindow("Tutorial 02");
InitializeGlutCallbacks();
// Must be done after glut is initialized!
GLenum res = glewInit();
if (res != GLEW_OK) {
fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
return 1;
}
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
CreateVertexBuffer();
glutMainLoop();
return 0;
}
저는 OpenGL에 대해 처음 보았습니다 만, 쉐이더가 필요한 "새로운"OpenGL과 비슷합니다. 꽤 좋은 튜토리얼을 위해 나는 [this one] (http://arcsynthesis.org/gltut/index.html)을 추천하고, [ "Hello triangle"] (http://arcsynthesis.org/gltut)을 읽고 싶을지도 모른다. /Basics/Tutorial%2001.html) 장. –
아마도 glClearColor()를 사용하여 전체 화면 색상을 변경하고 glClear'glLoadIdentity' 뒤에이 함수를 호출하십시오. – mr5
@RetoKoradi - 고마워요. – SINGULARITY