2014-04-06 1 views
1

첫 번째 OpenGL 쉐이더를 만들려고하지만 텍스처를 큐브 개체에 추가하려고 할 때 문제가 있습니다.C++에서 SDL OpenGL, 텍스처 셰이더가 텍스처를 누락했습니다.

아무도 날카로 워서 오류를 발견 할 수 있습니까? 코드에는 많은 오류가있을 수 있습니다. 누군가가 그 점을 지적하면 감사하지만, 회전 큐브가 회색이고 화려하지 않은 이유에 대해 가장 관심이 있습니다.

* 이 * 편집 알아 낸 (내가 미안, 낮은 소스 코드 크기를 유지하기 위해 처리하는 모든 오류를 건너 뛴) 좀 UV 설정,하지만 여전히 회색 큐브를 ... 놓친

#include <windows.h> 
#include <SDL.h> 

#include <GL/glew.h> 
#include <GL/glu.h> 
#include <GL/glut.h> 

#include <math.h> 
#include <string> 

using namespace std; 

void   initAll(); 
void   setupBox(); 
void   mainloop(); 
unsigned int generateTexture(); 
void   handle_inputs(); 
void   updateScreen(); 
void   clean_up(); 

int    scrWidth, scrHeight, flags; 
bool   bQuit = false; 
float   angle = 0.0f; 

GLuint   tex_Box, tex_Norm; 

std::string  vertex_source, fragment_source; 
GLuint   shader_program, vertex_shader, fragment_shader; 

// vao and vbo handle 
GLuint   vao, vbo; 

const char  *source; 
int    length; 

struct sVert 
{ 
    float x; 
    float y; 
    float z; 
}; 

class cPolygon 
{ 
public: 
    int v[4]; 

    void fillverts(int v1, int v2, int v3, int v4) { 
     v[0] = v1; 
     v[1] = v2; 
     v[2] = v3; 
     v[3] = v4; 
    } 
} p[6]; 

sVert pv[8]; 

int main(int argc, char *argv[]) 
{ 
    initAll(); 
    mainloop(); 
    clean_up(); 
    return 0; 
} 

void initAll() 
{ 
    scrWidth = 800; 
    scrHeight = 600; 

    vertex_source = 
     "#version 330\n" 
     "layout (location = 0) in vec3 Position;\n" 
     "layout (location = 1) in vec2 TexCoord;\n" 
     "void main() {\n" 
     " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" 
     " gl_TexCoord[0] = gl_MultiTexCoord0;\n" 
     "}\n"; 

    fragment_source = 
     "#version 330\n" 
     "uniform sampler2D tex;\n" 
     "void main() {\n" 
     " FragColor = texture2D(tex, gl_TexCoord[0].st);\n" 
     "}\n"; 

    SDL_InitSubSystem(SDL_INIT_VIDEO); 
    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); 
    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); 
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); 
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); 
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); 
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); 

    flags = SDL_OPENGL | SDL_ANYFORMAT ; 

    SDL_SetVideoMode(scrWidth, scrHeight, 16, flags); 

    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 
    gluPerspective(45.0f, (GLfloat)scrWidth/(GLfloat)scrHeight, 1.0f, 500.0f); 
    glMatrixMode(GL_MODELVIEW); 
    glLoadIdentity(); 

    glEnable (GL_DEPTH_TEST); 
    glEnable (GL_LIGHTING); 
    glEnable (GL_LIGHT0); 

    glEnable(GL_BLEND); 
    glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_ALPHA); 

    SDL_WM_SetCaption("Texture Shader", NULL); 

    glewInit(); 

    // Vertex shader 
    vertex_shader = glCreateShader(GL_VERTEX_SHADER); 
    source = vertex_source.c_str(); 
    length = vertex_source.size(); 
    glShaderSource(vertex_shader, 1, &source, &length); 
    glCompileShader(vertex_shader); 

    // Fragment shader 
    fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); 
    source = fragment_source.c_str(); 
    length = fragment_source.size(); 
    glShaderSource(fragment_shader, 1, &source, &length); 
    glCompileShader(fragment_shader); 

    // create program 
    shader_program = glCreateProgram(); 
    glAttachShader(shader_program, vertex_shader); 
    glAttachShader(shader_program, fragment_shader); 
    glLinkProgram(shader_program); 

    glGenVertexArrays(1, &vao); 
    glBindVertexArray(vao); 

    glGenBuffers(1, &vbo); 
    glBindBuffer(GL_ARRAY_BUFFER, vbo); 

    setupBox(); 

    GLfloat vd[6*5*6]; 

    for(int pi=0; pi<6; pi++) 
    { 
     vd[pi*30+ 0] = pv[ p[pi].v[0] ].x; 
     vd[pi*30+ 1] = pv[ p[pi].v[0] ].y; 
     vd[pi*30+ 2] = pv[ p[pi].v[0] ].z; 

     vd[pi*30+ 3] = 0.0; 
     vd[pi*30+ 4] = 1.0; 

     vd[pi*30+ 5] = pv[ p[pi].v[1] ].x; 
     vd[pi*30+ 6] = pv[ p[pi].v[1] ].y; 
     vd[pi*30+ 7] = pv[ p[pi].v[1] ].z; 

     vd[pi*30+ 8] = 0.0; 
     vd[pi*30+ 9] = 0.0; 

     vd[pi*30+10] = pv[ p[pi].v[2] ].x; 
     vd[pi*30+11] = pv[ p[pi].v[2] ].y; 
     vd[pi*30+12] = pv[ p[pi].v[2] ].z; 

     vd[pi*30+13] = 1.0; 
     vd[pi*30+14] = 0.0; 

     vd[pi*30+15] = pv[ p[pi].v[0] ].x; 
     vd[pi*30+16] = pv[ p[pi].v[0] ].y; 
     vd[pi*30+17] = pv[ p[pi].v[0] ].z; 

     vd[pi*30+18] = 0.0; 
     vd[pi*30+19] = 1.0; 

     vd[pi*30+20] = pv[ p[pi].v[2] ].x; 
     vd[pi*30+21] = pv[ p[pi].v[2] ].y; 
     vd[pi*30+22] = pv[ p[pi].v[2] ].z; 

     vd[pi*30+23] = 1.0; 
     vd[pi*30+24] = 0.0; 

     vd[pi*30+25] = pv[ p[pi].v[3] ].x; 
     vd[pi*30+26] = pv[ p[pi].v[3] ].y; 
     vd[pi*30+27] = pv[ p[pi].v[3] ].z; 

     vd[pi*30+28] = 1.0; 
     vd[pi*30+29] = 1.0; 
    } 

    glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*6*5*6, vd, GL_STATIC_DRAW); 
    glEnableVertexAttribArray(0); 
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5*sizeof(GLfloat), (char*)0 + 0*sizeof(GLfloat)); 
    glEnableVertexAttribArray(1); 
    glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5*sizeof(GLfloat), (char*)0 + 3*sizeof(GLfloat)); 

    tex_Box = generateTexture(); 
    tex_Norm = generateTexture(); 
} 

void setupBox() 
{ 
    for (int z=0;z<2;z++) 
    for (int y=0;y<2;y++) 
    for (int x=0;x<2;x++) 
    { 
     pv[x+y*2+z*4].x = -1.0+x; 
     pv[x+y*2+z*4].y = -1.0+y; 
     pv[x+y*2+z*4].z = -1.0+z; 
    } 

    p[0].fillverts (0, 1, 3, 2); // above 
    p[1].fillverts (4, 5, 1, 0); // behind 
    p[2].fillverts (6, 7, 3, 2); // in front 
    p[3].fillverts (5, 7, 3, 1); // right 
    p[4].fillverts (0, 2, 6, 4); // left 
    p[5].fillverts (7, 6, 4, 5); // below 
} 

unsigned int generateTexture() 
{ 
    BYTE data[128*128*3]; 
    unsigned int id; 

    for (int x=0;x<128;x++) 
     for (int y=0;y<128;y++) 
     { 
      data[y*128*3+x*3+0] = x;  // Red 
      data[y*128*3+x*3+1] = y;  // Green 
      data[y*128*3+x*3+2] = 128-(abs(64-x)+abs(64-y)); // Blue 
     } 

    glGenTextures(1, &id); 
    glBindTexture(GL_TEXTURE_2D, id); 
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 128, 128, 0, GL_RGB, GL_UNSIGNED_BYTE, data); 
    glGenerateMipmap(GL_TEXTURE_2D); 

    return id; 
} 

void mainloop() 
{ 
    while(bQuit == false) 
    { 
     handle_inputs(); 
     updateScreen(); 
     angle += 1.5f; 
     Sleep(50); 
    } 
} 

void handle_inputs() 
{ 
    SDL_PumpEvents(); 
    Uint8 * keystate = SDL_GetKeyState(NULL); 
    if(keystate[SDLK_ESCAPE]) bQuit = true; 
} 

void updateScreen() 
{ 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    glLoadIdentity(); 
    gluLookAt (2.0, 2.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); 
    glUseProgram(shader_program); 
    glBindVertexArray(vao); 

    glRotatef(angle, 1.0, 0.0, 0.0); //rotate on the x axis 
    glRotatef(angle, 0.0, 1.0, 0.0); //rotate on the y axis 
    glRotatef(angle, 0.0, 0.0, 1.0); //rotate on the z axis 

    glActiveTexture(GL_TEXTURE0); 
    int loc = glGetUniformLocation(shader_program, "tex"); 
    glUniform1i(loc, 0); 
    glBindTexture(GL_TEXTURE_2D, tex_Box); 
    glDrawArrays(GL_TRIANGLES, 0, 6*6); 
    //glutSolidTeapot(2.0); 
    glUseProgram(0); 
    SDL_GL_SwapBuffers(); 
} 

void clean_up() 
{ 
    glDeleteVertexArrays(1, &vao); 
    glDeleteBuffers(1, &vbo); 

    glDetachShader(shader_program, vertex_shader); 
    glDetachShader(shader_program, fragment_shader); 
    glDeleteShader(vertex_shader); 
    glDeleteShader(fragment_shader); 
    glDeleteProgram(shader_program); 

    SDL_QuitSubSystem(SDL_INIT_VIDEO); 
    glDeleteTextures(1, &tex_Box); 
    glDeleteTextures(1, &tex_Norm); 
    SDL_Quit(); 
} 

* *이 편집 2는 허용 대답 derhass 의 조언을 다음의 결과는 고정 된 버전이다. 만약 당신이 그것을 좋아한다면 그의 대답을 Upvote.

#include <windows.h> 
#include <SDL.h> 

#include <GL/glew.h> 
#include <GL/glu.h> 
#include <GL/glut.h> 
#include <stdio.h> 

#include <math.h> 
#include <string> 

using namespace std; 
#define LOG_SIZE 10000 

void   initAll(); 
void   setupBox(); 
void   mainloop(); 
unsigned int generateTexture(); 
void   handle_inputs(); 
void   updateScreen(); 
void   clean_up(); 
void   dbpf(int, const char *, ...); 

int    scrWidth, scrHeight, flags; 
bool   bQuit = false; 
float   angle = 0.0f; 

va_list   m; 
int    db_threashold = 0; 
GLint   status; 
GLchar   elog[LOG_SIZE]; 
GLint   rLength = 0; 

GLuint   tex_Box, tex_Norm; 

std::string  vertex_source, fragment_source; 
GLuint   shader_program, vertex_shader, fragment_shader; 

GLuint   vao, vbo; 

const char  *source; 
int    length; 

struct sVert 
{ 
    float x; 
    float y; 
    float z; 
}; 

class cPolygon 
{ 
public: 
    int v[4]; 

    void fillverts(int v1, int v2, int v3, int v4) { 
     v[0] = v1; 
     v[1] = v2; 
     v[2] = v3; 
     v[3] = v4; 
    } 
} p[6]; 

sVert pv[8]; 

int main(int argc, char *argv[]) 
{ 
    initAll(); 
    mainloop(); 
    clean_up(); 
    return 0; 
} 

void initAll() 
{ 
    scrWidth = 800; 
    scrHeight = 600; 

    vertex_source = 
     "#version 330\n" 
     "in vec3 Position;\n" 
     "in vec2 TexCoord;\n" 
     "out vec3 oColor;" 
     "out vec2 oTexcoord;" 
     "void main() {\n" 
     " oTexcoord = TexCoord;\n" 
     " gl_Position = gl_ModelViewProjectionMatrix*vec4(Position, 1.0);\n" 
     "}\n"; 

    fragment_source = 
     "#version 330\n" 
     "in vec2 oTexcoord;" 
     "out vec4 oColor;" 
     "uniform sampler2D tex;\n" 
     "void main() {\n" 
     " oColor = texture2D(tex, oTexcoord);\n" 
     "}\n"; 

    SDL_InitSubSystem(SDL_INIT_VIDEO); 
    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); 
    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); 
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); 
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); 
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); 
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); 

    flags = SDL_OPENGL | SDL_ANYFORMAT ; 

    SDL_SetVideoMode(scrWidth, scrHeight, 16, flags); 

    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 
    gluPerspective(45.0f, (GLfloat)scrWidth/(GLfloat)scrHeight, 1.0f, 500.0f); 
    glMatrixMode(GL_MODELVIEW); 
    glLoadIdentity(); 

    glEnable (GL_DEPTH_TEST); 
    glEnable (GL_LIGHTING); 
    glEnable (GL_LIGHT0); 

    SDL_WM_SetCaption("Texture Shader", NULL); 

    glewInit(); 

    // create and compiler vertex shader 
    vertex_shader = glCreateShader(GL_VERTEX_SHADER); 
    source = vertex_source.c_str(); 
    length = vertex_source.size(); 
    glShaderSource(vertex_shader, 1, &source, &length); 
    glCompileShader(vertex_shader); 

    glGetShaderiv(vertex_shader, GL_COMPILE_STATUS, &status); 
    glGetShaderInfoLog(vertex_shader, LOG_SIZE, &rLength, elog); 
    dbpf(10, "Compile vertex log: \n %s \n", elog); 

    // create and compiler fragment shader 
    fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); 
    source = fragment_source.c_str(); 
    length = fragment_source.size(); 
    glShaderSource(fragment_shader, 1, &source, &length); 
    glCompileShader(fragment_shader); 

    glGetShaderiv(fragment_shader, GL_COMPILE_STATUS, &status); 
    glGetShaderInfoLog(fragment_shader, LOG_SIZE, &rLength, elog); 
    dbpf(10, "Compile fragment log: \n %s \n", elog); 

    // create program 
    shader_program = glCreateProgram(); 

    // attach shaders 
    glAttachShader(shader_program, vertex_shader); 
    glAttachShader(shader_program, fragment_shader); 

    // link the program and check for errors 
    glLinkProgram(shader_program); 
    glGetProgramiv(shader_program, GL_LINK_STATUS, &status); 
    glGetProgramInfoLog(shader_program, LOG_SIZE, &rLength, elog); 
    dbpf(10, "Link log: \n %s \n", elog); 

    // generate and bind the vao 
    glGenVertexArrays(1, &vao); 
    glBindVertexArray(vao); 

    // generate and bind the buffer object 
    glGenBuffers(1, &vbo); 
    glBindBuffer(GL_ARRAY_BUFFER, vbo); 

    setupBox(); 

    GLfloat vd[6*5*6]; 

    for(int pi=0; pi<6; pi++) 
    { 
     vd[pi*30+ 0] = pv[ p[pi].v[0] ].x; 
     vd[pi*30+ 1] = pv[ p[pi].v[0] ].y; 
     vd[pi*30+ 2] = pv[ p[pi].v[0] ].z; 

     vd[pi*30+ 3] = 0.0; 
     vd[pi*30+ 4] = 1.0; 

     vd[pi*30+ 5] = pv[ p[pi].v[1] ].x; 
     vd[pi*30+ 6] = pv[ p[pi].v[1] ].y; 
     vd[pi*30+ 7] = pv[ p[pi].v[1] ].z; 

     vd[pi*30+ 8] = 0.0; 
     vd[pi*30+ 9] = 0.0; 

     vd[pi*30+10] = pv[ p[pi].v[2] ].x; 
     vd[pi*30+11] = pv[ p[pi].v[2] ].y; 
     vd[pi*30+12] = pv[ p[pi].v[2] ].z; 

     vd[pi*30+13] = 1.0; 
     vd[pi*30+14] = 0.0; 

     vd[pi*30+15] = pv[ p[pi].v[0] ].x; 
     vd[pi*30+16] = pv[ p[pi].v[0] ].y; 
     vd[pi*30+17] = pv[ p[pi].v[0] ].z; 

     vd[pi*30+18] = 0.0; 
     vd[pi*30+19] = 1.0; 

     vd[pi*30+20] = pv[ p[pi].v[2] ].x; 
     vd[pi*30+21] = pv[ p[pi].v[2] ].y; 
     vd[pi*30+22] = pv[ p[pi].v[2] ].z; 

     vd[pi*30+23] = 1.0; 
     vd[pi*30+24] = 0.0; 

     vd[pi*30+25] = pv[ p[pi].v[3] ].x; 
     vd[pi*30+26] = pv[ p[pi].v[3] ].y; 
     vd[pi*30+27] = pv[ p[pi].v[3] ].z; 

     vd[pi*30+28] = 1.0; 
     vd[pi*30+29] = 1.0; 
    } 

    // fill with data 
    glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*6*5*6, vd, GL_STATIC_DRAW); 

    // set up generic attrib pointers 
    glEnableVertexAttribArray(0); 
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5*sizeof(GLfloat), (char*)0 + 0*sizeof(GLfloat)); 

    glEnableVertexAttribArray(1); 
    glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5*sizeof(GLfloat), (char*)0 + 3*sizeof(GLfloat)); 

    tex_Box = generateTexture(); 
    tex_Norm = generateTexture(); 

} 

void setupBox() 
{ 

    for (int z=0;z<2;z++) 
    for (int y=0;y<2;y++) 
    for (int x=0;x<2;x++) 
    { 
     pv[x+y*2+z*4].x = -1.0+x; 
     pv[x+y*2+z*4].y = -1.0+y; 
     pv[x+y*2+z*4].z = -1.0+z; 
    } 

    p[0].fillverts (0, 1, 3, 2); // above 
    p[1].fillverts (4, 5, 1, 0); // behind 
    p[2].fillverts (6, 7, 3, 2); // in front 
    p[3].fillverts (5, 7, 3, 1); // right 
    p[4].fillverts (0, 2, 6, 4); // left 
    p[5].fillverts (7, 6, 4, 5); // below 
} 

unsigned int generateTexture() 
{ 
    BYTE data[128*128*3]; 
    unsigned int id; 

    for (int x=0;x<128;x++) 
     for (int y=0;y<128;y++) 
     { 
      data[y*128*3+x*3+0] = x;  // Red 
      data[y*128*3+x*3+1] = y;  // Green 
      data[y*128*3+x*3+2] = 128-(abs(64-x)+abs(64-y)); // Blue 
     } 

    glGenTextures(1, &id); 
    glBindTexture(GL_TEXTURE_2D, id); 
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 128, 128, 0, GL_RGB, GL_UNSIGNED_BYTE, data); 
    glGenerateMipmap(GL_TEXTURE_2D); 

    return id; 
} 

void mainloop() 
{ 
    while(bQuit == false) 
    { 
     handle_inputs(); 
     updateScreen(); 
     angle += 1.5f; 
     Sleep(50); 
    } 
} 

void handle_inputs() 
{ 
    SDL_PumpEvents(); 
    Uint8 * keystate = SDL_GetKeyState(NULL); 
    if(keystate[SDLK_ESCAPE]) bQuit = true; 
} 

void updateScreen() 
{ 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    glLoadIdentity(); 

    gluLookAt (2.0, 2.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); 

    // use the shader program 
    glUseProgram(shader_program); 

    // bind the vao 
    glBindVertexArray(vao); 

    // rotation 
    glRotatef(angle, 1.0, 0.0, 0.0); //rotate on the x axis 
    glRotatef(angle, 0.0, 1.0, 0.0); //rotate on the y axis 
    glRotatef(angle, 0.0, 0.0, 1.0); //rotate on the z axis 

    // bind texture 
    glActiveTexture(GL_TEXTURE0); 
    int loc = glGetUniformLocation(shader_program, "tex"); 
    glUniform1i(loc, 0); 
    glBindTexture(GL_TEXTURE_2D, tex_Box); 

    // draw 
    glDrawArrays(GL_TRIANGLES, 0, 6*6); 

    glUseProgram(0); 
    SDL_GL_SwapBuffers(); 
} 

void clean_up() 
{ 
    glDeleteVertexArrays(1, &vao); 
    glDeleteBuffers(1, &vbo); 

    glDetachShader(shader_program, vertex_shader); 
    glDetachShader(shader_program, fragment_shader); 
    glDeleteShader(vertex_shader); 
    glDeleteShader(fragment_shader); 
    glDeleteProgram(shader_program); 

    SDL_QuitSubSystem(SDL_INIT_VIDEO); 
    glDeleteTextures(1, &tex_Box); 
    glDeleteTextures(1, &tex_Norm); 
    SDL_Quit(); 
} 

void dbpf(int t, const char * msg, ...) 
{ 
    va_start(m, msg); 
    if (t >= db_threashold) vfprintf(stderr, msg, m); 
    va_end(m); 
} 
+0

Yikes, 나도 안다! 나는 UV 코드에 대해 완전히 잊어 버렸습니다. 그 이유가 무엇입니까? – GlamCasvaluir

답변

2

조각 쉐이더도 컴파일해서는 안됩니다. undeclated 변수 'FragColor'에 쓰고 있습니다. 먼저 코드를 추가하여 컴파일 및 링크 상태를 확인하고 컴파일 및 링크 로그를 쿼리하여 GLSL 컴파일러/링커가 감지 한 모든 오류 및 경고를 가져와야합니다. ,

GLint status; 
GLubyte log[LOG_SIZE]; 
// compile shader here 
... 
glGetShaderiv(shader, GL_COMPILE_STATUS, &status); 
if (status != GL_TRUE) { 
    // compile error 
    ... 
} 
glGetShaderInfoLog(shader, LOG_SIZE, 0, log); 
// print the log 

... 
// link the program here 
// ... 
glGetProgramiv(program, GL_LINK_STATUS, &status); 
if (status != GL_TRUE) { 
    // error 
    ... 
} 
glGetProgramInfoLog(program, LOG_SIZE, 0, log); 
// print the log 

어쩌면 당신은 단지 오류의 경우에는 정보 로그를 인쇄하고 싶지만, 심지어 성공적인 경우가 몇 가지 경고/힌트가있을 수 있습니다, 그래서 나는 alywas 인쇄하는 것이 좋습니다 : 당신은 같은 것을 사용할 수 있습니다 적어도 디버그/개발 빌트에서.

gl_TexCoord[0], gl_MultiTexCoord0 등과 같이 오래된 사용자 지정 속성, 입력 및 출력과 함께 더 이상 사용되지 않는 기본 제공을 혼합하지 않는 것이 좋습니다. 현재 신고 한 TexCoord 속성을 사용하고 있지 않습니다.

+0

감사합니다. 귀하의 explaination과 함께 오류 로그는 내가 마침내 그것을 얻을 수있었습니다! 나는 당신의 대답을 받아 들일 것이고 고정 된 버전을 게시 할 것입니다. Upvotes는 여기에 가서 대답 할 수 없습니다. – GlamCasvaluir