GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: No Line Numbers


Weird by ToraKoori
1
 
void Paint(void);
void doInit(void);

int    mainWindow;        
int    running;        
int    width, height;    

GLuint Indices[12] = {    0, 1, 2,
                        3, 4, 5,
                        6, 7, 8,
                        9, 10, 11};  

int main( int argc, char **argv )
{

    glfwInit();
    
    mainWindow = glfwOpenWindow(640, 480,    
    8, 8, 8,                                
    8,                                        
    24,                                        
    0,                                        
    GLFW_WINDOW);                            
    
    if(!mainWindow)                            
    {
        glfwTerminate();
        return 0;
    }

    doInit();
    
    do                                                    
    {
        Paint();                                        
        glfwSwapBuffers();                                
        running = !glfwGetKey( GLFW_KEY_ESC ) &&
                   glfwGetWindowParam( GLFW_OPENED );    
    } while(running);
    
    glfwTerminate();
    return 0;      
}

void doInit(void)
{

    glfwGetWindowSize( &width, &height );    
    height = height < 1 ? 1 : height;        

    glfwSetWindowTitle("Lighting Test");
    glfwEnable(GLFW_STICKY_KEYS);            
    
    glMatrixMode(GL_PROJECTION);            
    glLoadIdentity();                        
    

    
    gluPerspective(                            
    45.0,                                    
    (double)width/(double)height,            
    0.1,                                    
    100.0                                    
    );
    
    glMatrixMode(GL_MODELVIEW);                
    glLoadIdentity();                        
    
    glShadeModel(GL_SMOOTH);
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glDepthFunc(GL_LEQUAL);
    glEnable(GL_DEPTH_TEST);
    
    glEnable(GL_NORMALIZE);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    
    GLfloat Vertices[12][3] ={{-5.0, -5.0, 5.0},
                            {5.0, -5.0, 5.0},
                            {0.0, 5.0, 0.0},
                            {-5.0, -5.0, 5.0},
                            {5.0, -5.0, -5.0},
                            {0.0, 5.0, 0.0},
                            {-5.0, -5.0, -5.0},
                            {5.0, -5.0, -5.0},
                            {0.0, 5.0, 0.0},
                            {-5.0, -5.0, -5.0},
                            {-5.0, -5.0, 5.0},
                            {0.0, 5.0, 0.0},
                            };

    glVertexPointer(3,            
                    GL_FLOAT,    
                    0,            
                    Vertices    
                    ); 

    GLfloat Colors[12][3] =    {{0.0, 0.0, 0.3},
                            {0.0, 0.0, 0.3},
                            {0.0, 0.0, 0.0},
                            {0.0, 0.0, 0.3},
                            {0.0, 0.0, 0.3},
                            {0.0, 0.0, 0.0},
                            {0.0, 0.0, 0.3},
                            {0.0, 0.0, 0.3},
                            {0.0, 0.0, 0.0},
                            {0.0, 0.0, 0.3},
                            {0.0, 0.0, 0.3},
                            {0.0, 0.0, 0.0},
                            };

    glColorPointer(3,            
                    GL_FLOAT,    
                    0,            
                    Colors    
                    ); 
                    
    GLfloat Normals[12][3] ={{0.0, 0.5, 1.0},
                            {0.0, 0.5, 1.0},
                            {0.0, 0.5, 1.0},
                            
                            {1.0, 0.0, 1.0},
                            {1.0, 0.0, 1.0},
                            {1.0, 0.0, 1.0},
                            
                            {0.0, -0.5, 1.0},
                            {0.0, -0.5, 1.0},
                            {0.0, -0.5, 1.0},
                            
                            {-1.0, 0.5, 0.0},
                            {-1.0, 0.5, 0.0},
                            {-1.0, 0.5, 0.0},
                            };


    glNormalPointer(GL_FLOAT,    
                    0,            
                    Normals    
                    );  

}

void Paint(void)                            
{
    double t;                                
    t = glfwGetTime();                        

    glViewport( 0, 0, width, height );        
    
    glClear(GL_COLOR_BUFFER_BIT |
            GL_DEPTH_BUFFER_BIT);            
    glLoadIdentity();                        
    
    glTranslatef(0.0f, 0.0f, -20.0f);
    glRotatef(90 * (float)t, 0.0, 1.0, 0.0);
    
    glDrawElements(    GL_TRIANGLES,            
                    12,                    
                    GL_UNSIGNED_INT,    
                    Indices                
                    ); 

}