#define GL_GLEXT_PROTOTYPES #include #if 1 static const GLchar *source[] = { "void main() {\n", " gl_Position = ftransform();\n", " if (gl_Vertex.xy == vec2(-1, -1)) {\n", " gl_FrontColor.rgb = vec3(0, 0, 1);\n", " } else {\n", " gl_FrontColor.rg = (gl_Vertex.xy + vec2(1, 1)) * 0.5;\n", " }\n", "}\n", }; #else static const GLchar *source[] = { "void main() {\n", " gl_Position = ftransform();\n", " if (gl_Vertex.xy == vec2(-1, -1)) {\n", " gl_FrontColor.rgb = vec3(0, 0, 1);\n", " return;\n", " }\n", " gl_FrontColor.rg = (gl_Vertex.xy + vec2(1, 1)) * 0.5;\n", "}\n", }; #endif static void display(void){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glBegin(GL_QUADS); glVertex2f(-1, -1); glVertex2f(-1, 1); glVertex2f(1, 1); glVertex2f(1, -1); glEnd(); glFinish(); } static void reshape(int width, int height){ glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); } int main(int argc, char **argv){ GLuint shader, program; glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB); glutCreateWindow(argv[0]); glutDisplayFunc(display); glutReshapeFunc(reshape); shader = glCreateShader(GL_VERTEX_SHADER); glShaderSource(shader, sizeof(source) / sizeof(source[0]), source, NULL); glCompileShader(shader); program = glCreateProgram(); glAttachShader(program, shader); glLinkProgram(program); glUseProgram(program); glutMainLoop(); return 0; }