2017-11-13 5 views
0

그래서 내 대학 강사가 우리에게이 코드를 알려 주었고 작동하지 않습니다. 결코 없었으며 지금까지 아무도 작동하지 못했습니다. 우리는 어리 석고 있습니까? 강사가 우리에게 깨진 자료를 줬나요? 나는 진지하게 이것을 이해할 수없고 도움이 필요하다. 나는 많은 실수를 고치는 데 부분적으로 관여했다. 그러나 그 후에 문제는 '100 % 일하는'코드 임에도 불구하고 해결하기가 더 어려워졌다. ... side note : 모든 디렉토리의 형식이 올바르지 만 추가 종속성은 내가 아는 한 정확하게 설정되었습니다.GLFW - 많은 오류가이 코드

//First Shader Handling Program 

#include "stdafx.h" 

#include "gl_core_4_3.hpp" 

#include <GLFW/glfw3.h> 

int _tmain(int argc, _TCHAR* argv[]) 
{ 
    //Select the 4.3 core profile 
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); 
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, TRUE); 
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 

    //Start the OpenGL context and open a window using the //GLFW helper library 

    if (!glfwInit()) { 
     fprintf(stderr, "ERROR: could not start GLFW3\n"); 
     glfwTerminate(); 
     return 1; 
    } 

    GLFWwindow* window = glfwCreateWindow(640, 480, "First GLSL Triangle", NULL, NULL); 

    if (!window) { 
     fprintf(stderr, "ERROR: could not open window with GLFW3\n"); 
     glfwTerminate(); 
     return 1; 
    } 

    glfwMakeContextCurrent(window); 


    //Load the OpenGL functions for C++ gl::exts::LoadTest didLoad = gl::sys::LoadFunctions(); if (!didLoad) { 
    //Load failed 
    fprintf(stderr, "ERROR: GLLoadGen failed to load functions\n"); 

    glfwTerminate(); 
    return 1; 
} 

printf("Number of functions that failed to load : %i.\n", didLoad.GetNumMissing()); 

//Tell OpenGL to only draw a pixel if its shape is closer to //the viewer 

//i.e. Enable depth testing with smaller depth value //interpreted as being closer gl::Enable(gl::DEPTH_TEST); gl::DepthFunc(gl::LESS); 

//Set up the vertices for a triangle 
float points[] = { 
    0.0f, 0.5f, 0.0f, 
    0.5f, -0.5f, 0.0f, 
    -0.5f, -0.5f, 0.0f 
}; 


//Create a vertex buffer object to hold this data GLuint vbo=0; 

gl::GenBuffers(1, &vbo); 
gl::BindBuffer(gl::ARRAY_BUFFER, vbo); 
gl::BufferData(gl::ARRAY_BUFFER, 9 * sizeof(float), points, 
    gl::STATIC_DRAW); 


//Create a vertex array object 
GLuint vao = 0; 
gl::GenVertexArrays(1, &vao); 
gl::BindVertexArray(vao); 
gl::EnableVertexAttribArray(0); 
gl::BindBuffer(gl::ARRAY_BUFFER, vbo); 
gl::VertexAttribPointer(0, 3, gl::FLOAT, FALSE, 0, NULL); 

//The shader code strings which later we will put in //separate files 

//The Vertex Shader 
const char* vertex_shader = 
"#version 400\n" 
"in vec3 vp;" 
"void main() {" 
     " gl_Position = vec4(vp, 1.0);" 
"}"; 

//The Fragment Shader 
const char* fragment_shader = 
"#version 400\n" 
"out vec4 frag_colour;" 

"void main() {" 
     " frag_colour = vec4(1.0, 0.5, 0.0, 1.0);" 
"}"; 

//Load the strings into shader objects and compile GLuint vs = gl::CreateShader(gl::VERTEX_SHADER); gl::ShaderSource(vs, 1, &vertex_shader, NULL); gl::CompileShader(vs); 

GLuint fs = gl::CreateShader(gl::FRAGMENT_SHADER); gl::ShaderSource(fs, 1, &fragment_shader, NULL); gl::CompileShader(fs); 

//Compiled shaders must be compiled into a single executable //GPU shader program 

//Create empty program and attach shaders GLuint shader_program = gl::CreateProgram(); gl::AttachShader(shader_program, fs); gl::AttachShader(shader_program, vs); gl::LinkProgram(shader_program); 

//Now draw 
while (!glfwWindowShouldClose(window)) { 
    //Clear the drawing surface 
    gl::Clear(gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT); 
    gl::UseProgram(shader_program); 
    gl::BindVertexArray(vao); 

    //Draw point 0 to 3 from the currently bound VAO with 
    //current in-use shader 
    gl::DrawArrays(gl::TRIANGLES, 0, 3); 

    //update GLFW event handling 
    glfwPollEvents(); 

    //Put the stuff we have been drawing onto the display glfwSwapBuffers(window); 

} 

//Close GLFW and end 
glfwTerminate(); 

return 0; 

} 
+2

오류가 게시되는 것이 가장 좋습니다. 질문을 편집 할 수 있습니다. –

+2

중요한 코드가 주석 처리 된 곳이 꽤 있습니다. (필자는 이것이 개행을 제거한 복사 & 붙여 넣기 작업 중 또는 개조 된 개식 전환을 통해 일어난 것으로 의심됩니다.) – molbdnilo

+1

실제로 어떤 종류의 EOL 변환 실패의 결과처럼 보입니다. – VTT

답변

0

라인 엔딩이 맹 글링 된 것으로 보입니다.

실제 코드가 두 줄로 나누어지지 않은 코드가 여러 줄이므로 코드가 주석과 같은 줄에 있으므로 실행되지 않습니다. 적절한 줄 끝자리가있는 프로그램입니다.

//First Shader Handling Program 

#include "stdafx.h" 

#include "gl_core_4_3.hpp" 

#include <GLFW/glfw3.h> 

int _tmain(int argc, _TCHAR* argv[]) 
{ 
    //Select the 4.3 core profile 
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); 
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, TRUE); 
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 

    //Start the OpenGL context and open a window using the 
    //GLFW helper library 

    if (!glfwInit()) { 
     fprintf(stderr, "ERROR: could not start GLFW3\n"); 
     glfwTerminate(); 
     return 1; 
    } 

    GLFWwindow* window = glfwCreateWindow(640, 480, "First GLSL Triangle", NULL, NULL); 

    if (!window) { 
     fprintf(stderr, "ERROR: could not open window with GLFW3\n"); 
     glfwTerminate(); 
     return 1; 
    } 

    glfwMakeContextCurrent(window); 


    //Load the OpenGL functions for C++ 
    gl::exts::LoadTest didLoad = gl::sys::LoadFunctions(); 
    if (!didLoad) { 
     //Load failed 
     fprintf(stderr, "ERROR: GLLoadGen failed to load functions\n"); 

     glfwTerminate(); 
     return 1; 
    } 

printf("Number of functions that failed to load : %i.\n", didLoad.GetNumMissing()); 

//Tell OpenGL to only draw a pixel if its shape is closer to 
//the viewer 

//i.e. Enable depth testing with smaller depth value 
//interpreted as being closer 
gl::Enable(gl::DEPTH_TEST); 
gl::DepthFunc(gl::LESS); 

//Set up the vertices for a triangle 
float points[] = { 
    0.0f, 0.5f, 0.0f, 
    0.5f, -0.5f, 0.0f, 
    -0.5f, -0.5f, 0.0f 
}; 

//Create a vertex buffer object to hold this data 
GLuint vbo=0; 

gl::GenBuffers(1, &vbo); 
gl::BindBuffer(gl::ARRAY_BUFFER, vbo); 
gl::BufferData(gl::ARRAY_BUFFER, 9 * sizeof(float), points, gl::STATIC_DRAW); 

//Create a vertex array object 
GLuint vao = 0; 
gl::GenVertexArrays(1, &vao); 
gl::BindVertexArray(vao); 
gl::EnableVertexAttribArray(0); 
gl::BindBuffer(gl::ARRAY_BUFFER, vbo); 
gl::VertexAttribPointer(0, 3, gl::FLOAT, FALSE, 0, NULL); 

//The shader code strings which later we will put in 
//separate files 

//The Vertex Shader 
const char* vertex_shader = 
"#version 400\n" 
"in vec3 vp;" 
"void main() {" 
     " gl_Position = vec4(vp, 1.0);" 
"}"; 

//The Fragment Shader 
const char* fragment_shader = 
"#version 400\n" 
"out vec4 frag_colour;" 

"void main() {" 
     " frag_colour = vec4(1.0, 0.5, 0.0, 1.0);" 
"}"; 

//Load the strings into shader objects and compile 
GLuint vs = gl::CreateShader(gl::VERTEX_SHADER); 
gl::ShaderSource(vs, 1, &vertex_shader, NULL); 
gl::CompileShader(vs); 

GLuint fs = gl::CreateShader(gl::FRAGMENT_SHADER); 
gl::ShaderSource(fs, 1, &fragment_shader, NULL); 
gl::CompileShader(fs); 

//Compiled shaders must be compiled into a single executable 
//GPU shader program 

//Create empty program and attach shaders 
GLuint shader_program = gl::CreateProgram(); 
gl::AttachShader(shader_program, fs); 
gl::AttachShader(shader_program, vs); 
gl::LinkProgram(shader_program); 

//Now draw 
while (!glfwWindowShouldClose(window)) { 
    //Clear the drawing surface 
    gl::Clear(gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT); 
    gl::UseProgram(shader_program); 
    gl::BindVertexArray(vao); 

    //Draw point 0 to 3 from the currently bound VAO with 
    //current in-use shader 
    gl::DrawArrays(gl::TRIANGLES, 0, 3); 

    //update GLFW event handling 
    glfwPollEvents(); 

    //Put the stuff we have been drawing onto the display 
    glfwSwapBuffers(window); 
} 

//Close GLFW and end 
glfwTerminate(); 

return 0; 
}