PDA

View Full Version : GLSL Color not working...



yj1214
08-06-2015, 02:22 PM
I followed everything and copied exact same code from Jamie King's tutorial...

here's my code


main.cpp


#include few stuffs
.
.
.

extern const char *vertexShaderCode;
extern const char *fragmentShaderCode;


int main(){
bla bla bla...
make window();
initGL();
}

initGL(){
setGlData(); //all my vertex stuffs...
setShader();
}
void setShader(){
GLuint vertexShaderID = glCreateShader(GL_VERTEX_SHADER);
GLuint fragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);

const char *adapter[1];
adapter[0] = vertexShaderCode;
glShaderSource(vertexShaderID, 1, adapter, 0);
adapter[0] = fragmentShaderCode;
glShaderSource(fragmentShaderID, 1, adapter, 0);

glCompileShader(vertexShaderID);
glCompileShader(fragmentShaderID);

GLuint programID = glCreateProgram();
glAttachShader(programID, vertexShaderID);
glAttachShader(programID, fragmentShaderID);
glLinkProgram(programID);

glUseProgram(programID);
}




shader_code.cpp


const char *vertexShaderCode =
"#version 430\r\n"
""
""
"in layout(location = 0) vec2 position;"
""
"void main(){"
" gl_position = vec4(position, 0.0, 1.0);"
"}";

const char *fragmentShaderCode =
"#version 430\r\n"
""
""
"out vec4 tColor;"
""
"void main(){"
" tColor = vec4(0.0, 1.0, 0.0, 1.0);"
"}";



What's my problem? when I run my program, it's only showing white color...

yj1214
08-06-2015, 09:00 PM
SOLVED


typo error...


gl_position should be
gl_Position