2013-04-27 2 views
0

Archsynthetics '프라이머를주고 안녕하세요 삼각형 장을 읽고 LWJGL로 점프하기로 결정했습니다. 처음 시도한 후에 화면에 아무 것도 표시하지 못했을 때 다시 C++ 코드를 다른 GL 3.x tutorial에서 이식하려고 노력했습니다.간단한 LWJGL 프로그램이 아무것도 표시하지 않습니다

내가 알 수있는 한, 모든 부품을 함께 가지고 있지만 화면은 여전히 ​​검은 색입니다. 나는 그 개념을 이해하지만, 나는 여기서 간단한 것을 놓치고 있다고 확신한다.

가능한 한 간단하게 잘라 냈습니다. 다음 클래스는 this shader helper을 사용하며 예상 한대로 작동한다고 말할 수 있습니다 (오류 검사 부족 - 이외에도 쉐이더 컴파일을 보장 함).

public class HelloTriangle31 { 
    public static void main(String[] args) throws LWJGLException, InterruptedException, IOException 
    { 
     // Setup display mode (size) 
     Display.setDisplayMode(new DisplayMode(800, 600)); 

     // Set context settings 
     // Basically forces 3.1 
     ContextAttribs contextAttributes = new ContextAttribs(3, 2) 
     .withForwardCompatible(true) 
     .withProfileCompatibility(false) 
     .withProfileCore(true); 
     Display.create(new PixelFormat(), contextAttributes); 
     Display.setResizable(false); 
     Display.setVSyncEnabled(true); 

     // Log some stuff 
     System.out.println("OpenGL version: " + GL11.glGetString(GL11.GL_VERSION));  

     // Setup 
    String vertexStr = readEntireFile(new File("vertex32.gl")); 
    int vertexID = ShaderUtils.makeShader(vertexStr, GL20.GL_VERTEX_SHADER); 
    String fragStr = readEntireFile(new File("fragment32.gl")); 
    int fragID = ShaderUtils.makeShader(fragStr, GL20.GL_FRAGMENT_SHADER); 
    int program = GL20.glCreateProgram(); 
     GL20.glAttachShader(program, vertexID); 
     GL20.glAttachShader(program, fragID); 
     GL20.glBindAttribLocation(program, 0, "in_Position"); 
     GL20.glBindAttribLocation(program, 1, "in_Color"); 
     GL20.glLinkProgram(program); 

     FloatBuffer vertexFloats = BufferUtils.createFloatBuffer(9); 
     assert(vertexFloats.capacity() == 9); 
     vertexFloats.put(new float[]{ 
      -0.3f, 0.5f, 0f, 
      -0.8f, -0.5f, 0f, 
      0.2f, -0.5f, 0f 
     }); 

     FloatBuffer colorFloats = BufferUtils.createFloatBuffer(9); 
     assert(colorFloats.capacity() == 9); 
     colorFloats.put(new float[]{ 
      1.0f, 0.0f, 0.0f, 
      0.0f, 1.0f, 0.0f, 
      0.0f, 0.0f, 1.0f 
     }); 

     IntBuffer vertexArrayInts = BufferUtils.createIntBuffer(1); 
     assert(vertexArrayInts.capacity() == 1); 
     GL30.glGenVertexArrays(vertexArrayInts); 
     GL30.glBindVertexArray(vertexArrayInts.get(0)); 

     IntBuffer vertexBufferInts = BufferUtils.createIntBuffer(2); 
     assert(vertexBufferInts.capacity() == 2); 
     GL15.glGenBuffers(vertexBufferInts); 

     GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertexBufferInts.get(0)); 
     GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertexFloats, GL15.GL_STATIC_DRAW); 
     GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0); 
     GL20.glEnableVertexAttribArray(0); 

     GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertexBufferInts.get(1)); 
     GL15.glBufferData(GL15.GL_ARRAY_BUFFER, colorFloats, GL15.GL_STATIC_DRAW); 
     GL20.glVertexAttribPointer(1, 3, GL11.GL_FLOAT, false, 0, 0); 
     GL20.glEnableVertexAttribArray(1); 

     GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); 
     GL30.glBindVertexArray(0); 

     GL11.glViewport(0, 0, 800, 600); 

     GL20.glUseProgram(program); 

     // Main loop 
     while(!Display.isCloseRequested()) 
     { 
      GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); 
      GL30.glBindVertexArray(vertexArrayInts.get(0)); 
      GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 3); 
      GL30.glBindVertexArray(0); 

      Display.update(); 
     } 

     Display.destroy(); 
    } 

    private static String readEntireFile(File file) throws IOException 
    { 
     // Open input stream 
     FileInputStream fis = new FileInputStream(file); 
     try 
     { 
      byte[] buffer = new byte[(int) file.length()]; 
      int len = fis.read(buffer); 
      return new String(buffer, 0, len); 
     }finally{ 
      if(fis != null) fis.close(); 
     } 
    } 
} 

vertex32.gl :

#version 140 

in vec3 in_Position; 
in vec3 in_Color; 
out vec3 ex_Color; 

void main(void) 
{ 
     gl_Position = vec4(in_Position, 1.0); 
     ex_Color = in_Color; 
} 

fragment32.gl :

#version 140 

precision highp float; // needed only for version 1.30 

in vec3 ex_Color; 
out vec4 out_Color; 

void main(void) 
{ 
     out_Color = vec4(ex_Color,1.0); 
} 

내가 잘못된거야 어디에 있는지에 실패하고있다. 오류 없음, 유일한 출력은 OpenGL 3.2 - 을 올바르게 표시하는 버전 문자열입니다. 명시 적 컨텍스트 특성을 사용하거나 사용하지 않고 시도했습니다.

제가 따라 한 모든 튜토리얼에서 이상한 점은 예를 들어 glOrtho을 사용하여 프로젝션 매트릭스가 설정되지 않았기 때문입니다. LWJGL (GL 1.1 기능을 사용하는) 응용 프로그램은 glOrtho으로 작동하지만 이제는 업그레이드/재배치/내 GL 지식을 수정하려고합니다. 다시 사각형으로 돌아갑니다.

무엇이 누락 되었습니까?

편집 :가 갖는 VM 인수 -Dorg.lwjgl.util.Debug=true 정의 수율 :

[LWJGL] Initial mode: 1920 x 1080 x 32 @60Hz 
[LWJGL] MemoryUtil Accessor: AccessorUnsafe 
[LWJGL] GL_ARB_gpu_shader_fp64 was reported as available but an entry point is missing 
[LWJGL] GL_ARB_shader_subroutine was reported as available but an entry point is missing 
[LWJGL] GL_ARB_vertex_attrib_64bit was reported as available but an entry point is missing 
OpenGL version: 3.2.0 
+1

"* 버전 1.30 *에서만 필요합니다."* 모든 버전의 데스크탑 GL에는 필요하지 않습니다. 사실 데스크톱 GL에서는 * 아무것도하지 않습니다. –

+0

@NicolBolas 셰이더는 말 그대로 복사/붙여 넣기되었습니다. 제 코멘트가 아닙니다, ㅎ. – Qix

+0

당신이 작업하고 있다고 말하는 것과 다른 튜토리얼 *에서 셰이더를 복사하여 붙여 넣는 이유는 무엇입니까? –

답변

0

난 당신이 in_Position이 속성이 0이고 in_Color이 속성 문제의 튜토리얼이하는 1이라고 OpenGL을 말할 부분이 표시되지 않습니다 그 쉐이더는 layout(location) 문법으로되어 있습니다.

구문을 사용할 수 없거나 사용하지 않는 경우 glBindAttribLocation calls으로 처리해야합니다. 쉐이더를 연결하는 중입니다.

+0

아직 아무것도 (업데이트 된 코드 확인). – Qix

관련 문제