Esempio n. 1
0
static void
Init(void)
{
   if (!ShadersSupported())
      exit(1);

   vertShader = CompileShaderText(GL_VERTEX_SHADER, VertShaderText);
   fragShader = CompileShaderText(GL_FRAGMENT_SHADER, FragShaderText);
   program = LinkShaders(vertShader, fragShader);

   glUseProgram(program);

   SetUniformValues(program, Uniforms);
   PrintUniforms(Uniforms);

   assert(glGetError() == 0);

   glClearColor(0.4f, 0.4f, 0.8f, 0.0f);

   printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));

   assert(glIsProgram(program));
   assert(glIsShader(fragShader));
   assert(glIsShader(vertShader));

   glColor3f(1, 0, 0);
}
Esempio n. 2
0
static void menu_selected(int entry)
{
    switch (entry) {
    case QUIT:
        exit(0);
        break;
    default:
        Uniforms[0].value[0] = entry;
    }

    SetUniformValues(program, Uniforms);
    glutPostRedisplay();
}
Esempio n. 3
0
static void
Init(void)
{
   if (!ShadersSupported())
      exit(1);

   vertShader = CompileShaderFile(GL_VERTEX_SHADER, VertProgFile);
   fragShader = CompileShaderFile(GL_FRAGMENT_SHADER, FragProgFile);
   program = LinkShaders(vertShader, fragShader);

   glUseProgram(program);

   SetUniformValues(program, Uniforms);
   PrintUniforms(Uniforms);

   assert(glGetError() == 0);

   glClearColor(0.4f, 0.4f, 0.8f, 0.0f);

   glEnable(GL_DEPTH_TEST);

   glColor3f(1, 0, 0);
}
Esempio n. 4
0
static void init(void)
{
    static const char *fragShaderText =
        "void main() {\n"
        "    gl_FragColor = gl_Color;\n"
        "}\n";
    static const char *vertShaderText =
        "void main() {\n"
        "   gl_FrontColor = gl_Color;\n"
        "   gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
        "}\n";
    static const char *geoShaderText =
        "#version 120\n"
        "#extension GL_ARB_geometry_shader4 : enable\n"
        "void main()\n"
        "{\n"
        "  for(int i = 0; i < gl_VerticesIn; ++i)\n"
        "  {\n"
        "    gl_FrontColor = gl_FrontColorIn[i];\n"
        "    gl_Position = gl_PositionIn[i];\n"
        "    EmitVertex();\n"
        "  }\n"
        "}\n";


    if (!ShadersSupported())
        exit(1);

    if (!glutExtensionSupported("GL_ARB_geometry_shader4")) {
        printf("This demo requires GL_ARB_geometry_shader4\n");
        exit(1);
    }

    menu_init();

    fragShader = glCreateShader(GL_FRAGMENT_SHADER);
    load_and_compile_shader(fragShader, fragShaderText);

    vertShader = glCreateShader(GL_VERTEX_SHADER);
    load_and_compile_shader(vertShader, vertShaderText);

    geoShader = glCreateShader(GL_GEOMETRY_SHADER_ARB);
    if (filename)
        read_shader(geoShader, filename);
    else
        load_and_compile_shader(geoShader,
                                geoShaderText);

    program = glCreateProgram();
    glAttachShader(program, vertShader);
    glAttachShader(program, geoShader);
    glAttachShader(program, fragShader);

    glProgramParameteriARB(program, GL_GEOMETRY_INPUT_TYPE_ARB,
                           GL_LINES_ADJACENCY_ARB);
    glProgramParameteriARB(program, GL_GEOMETRY_OUTPUT_TYPE_ARB,
                           GL_LINE_STRIP);

    {
        int temp;
        glGetIntegerv(GL_MAX_GEOMETRY_OUTPUT_VERTICES_ARB,&temp);
        glProgramParameteriARB(program,GL_GEOMETRY_VERTICES_OUT_ARB,temp);
    }

    glLinkProgram(program);
    check_link(program);
    glUseProgram(program);

    SetUniformValues(program, Uniforms);
    PrintUniforms(Uniforms);

    assert(glGetError() == 0);

    glEnableClientState( GL_VERTEX_ARRAY );
    glEnableClientState( GL_COLOR_ARRAY );

    glVertexPointer( 3, GL_FLOAT, sizeof(vertices[0]), vertices );
    glColorPointer( 4, GL_FLOAT, sizeof(color[0]), color );
}