2016-12-24 6 views
0

lwjgl을 사용하여 몇 가지 팅크 작업을하고 일부 2 차원 도형을 만듭니다. 내가 뭘 잘못하고 있는지 모르지만 화면의 첫 번째 녹색 사각형보다 더 많이 보여줄 수는 없습니다. 내 창 루프 함수 코드는 다음과 같습니다.LWJGL : OpenGL에서 둘 이상의 도형을 렌더링 할 수 없습니다.

private void loop() { 
// This line is critical for LWJGL's interoperation with GLFW's 
// OpenGL context, or any context that is managed externally. 
// LWJGL detects the context that is current in the current thread, 
// creates the GLCapabilities instance and makes the OpenGL 
// bindings available for use. 
GL.createCapabilities(); 
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); 
glOrtho(0, vidmode.width(),0, vidmode.height(),-1,1); 

// Set the clear color 
glClearColor(.0f, 0.6f, 0.6f, 0.0f); 


// Run the rendering loop until the user has attempted to close 
// the window or has pressed the ESCAPE key. 
while (!glfwWindowShouldClose(window) && !dataH.isGameOver()) { 


    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the framebuffer 

    glBegin(GL_QUADS); 
    { 
     glColor3f(0.1f, 1.0f, 0.1f); // Green 
     glVertex2d(xMapCentre - 100,yMapCentre - 100); 
     glVertex2d(xMapCentre - 100,yMapCentre + 100); 
     glVertex2d(xMapCentre + 100,yMapCentre + 100); 
     glVertex2d(xMapCentre + 100,yMapCentre - 100); 

     glColor3f(0.2f, 0.2f, 0.2f); // Dark Gray 
     glVertex2f(-0.9f, -0.7f); 
     glColor3f(1.0f, 1.0f, 1.0f); // White 
     glVertex2f(-0.5f, -0.7f); 
     glColor3f(0.2f, 0.2f, 0.2f); // Dark Gray 
     glVertex2f(-0.5f, -0.3f); 
     glColor3f(1.0f, 1.0f, 1.0f); // White 
     glVertex2f(-0.9f, -0.3f); 
    } 
    glEnd(); 



    glBegin(GL_TRIANGLES);   // Each set of 3 vertices form a triangle 
    { 
    glColor3f(0.0f, 0.0f, 1.0f); // Blue 
    glVertex2f(0.1f, -0.6f); 
    glVertex2f(0.7f, -0.6f); 
    glVertex2f(0.4f, -0.1f); 

    glColor3f(1.0f, 0.0f, 0.0f); // Red 
    glVertex2f(0.3f, -0.4f); 
    glColor3f(0.0f, 1.0f, 0.0f); // Green 
    glVertex2f(0.9f, -0.4f); 
    glColor3f(0.0f, 0.0f, 1.0f); // Blue 
    glVertex2f(0.6f, -0.9f); 
    } 
    glEnd(); 


    glfwSwapBuffers(window); // swap the color buffers 
    // Poll for window events. The key callback above will only be 
    // invoked during this call. 
    glfwPollEvents(); 
} 
} 

도움이 될만한 질문이 있는데 너무 애매한 경우 알려주십시오. 감사.

답변

1

일반적으로 3D 공간에서 2D 구조를 렌더링 할 때 후면면 컬링 glDisable(GL_CULL_FACE)을 비활성화해야합니다. 그렇지 않으면 한 쪽에서 만 볼 수 있습니다. 셰이더에서 정상적인 방향을 알아야합니다.

2D 만있는 경우, 뒤 또는 앞면 컬링을 원할 경우 삼각형의 와인딩 순서를 확인하고 시계 반대 방향 및 시계 방향으로 각각 glFontFace(GL_CCW) 또는 glFrontFace(GL_CW)을 설정하십시오. (굴곡 순서가 glVertex2f을 사용할 때 2D에서 차이가 나는지 확인하지 못할 수도 있습니다.)

또한 깊이 테스트 및 깊이 쓰기를 시도해보십시오. glDisable(GL_DEPTH_TEST)glDepthMask(GL_FALSE).