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


A Paste by Anonymous
1
 
#include <windows.h>
#include <GL/gl.h>
#include <GL/glut.h>
#include <GL/glu.h>

//#include <windows.h>

float angle = 0.0f, x, m = 0.0f ,i = 0.0f;
GLfloat red = 1.0 , green = 1.0 , blue = 1.0, z = 1.0;

#pragma comment( lib, "opengl32.lib" )
#pragma comment( lib, "glu32.lib" )
#pragma comment( lib, "glut32.lib" )

void ReSizeGLScene(int Width, int Height)
{

  glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
  glLoadIdentity();
 // glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix

}
void direction(GLint way)
{
    switch (way)
    {
    case 1: //Cw
        z = 1.0;
        break;
    case 2://CCW
        z = -1.0;
        break;
    }

}

void speed_menu(GLint speed)
{
    switch (speed)
    {
    case 1: //slow
        m = 1.5f;
        break;
    case 2://med
        m = 3.5;
        break;
    case 3: //high
        m = 10.0f;
        break;
    }

}
void colors_menu(GLint coloropt)
{
    switch (coloropt)
    {
    case 1:
        red = 1.0 , green = 0.0 , blue = 0.0;
            break;
    case 2:
        red = 1.0 , green = 1.0 , blue = 0.0;
            break;
    case 3:
        red = 0.0 , green = 0.0 , blue = 1.0;
            break;
    case 4:
        red = 0.0 , green = 1.0 , blue = 0.0;
            break;
    }
    glutPostRedisplay();
}
void Right_menu(int)
{
}
void haw(GLint hawz)
{
    switch (hawz)
    {
    case 1:
    
    break;
    }
}
void rot_menu(GLint rotate)
{
    switch (rotate)
    {    
    case 1:
        m = x;
        break;
    case 2:
        x = m;
        m = 0.0;
        break;
    }
}
void update()
{ angle+=m;}


void draw(void)
    {
    glLoadIdentity();
    //update();
    angle=angle+0.1f;
    glRotatef(angle,0.0f,0.0,1.0);
    
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_QUADS); // num 1
    glColor3f(red,green,blue);
    glVertex3f(200.0,200.0,50.0);
    glVertex3f(300.0,220.0,50.0);
    glVertex3f(300.0,180.0,50.0);
    glVertex3f(200.0,200.0,50.0);
//    glVertex3f(200.0,200.0,-50.0);
//    glVertex3f(300.0,220.0,-50.0);
//    glVertex3f(300.0,180.0,-50.0);
//    glVertex3f(200.0,200.0,-50.0);
    
     // num 2
    glVertex2f(200.0,200.0);
    glVertex2f(180.0,300.0);
    glVertex2f(220.0,300.0);
    glVertex2f(200.0,200.0);

     //num 3
    glVertex2f(200.0,200.0);
    glVertex2f(100.0,220.0);
    glVertex2f(100.0,180.0);
    glVertex2f(200.0,200.0);    

     // num 4
    glVertex2f(200.0,200.0);
    glVertex2f(180.0,110.0);
    glVertex2f(220.0,110.0);
    glVertex2f(200.0,200.0);
    glEnd();
    
    glutSwapBuffers();
    glutPostRedisplay();

//    re= m;
}

void main()
{
    GLint colMenu, rotation, speed_rot, hawhaw, rotdirec;
    glutInitDisplayMode(GLUT_DOUBLE);
    glutInitWindowSize(400,400);
    glutCreateWindow("Project");
    glutDisplayFunc(draw);
    glutIdleFunc(&update);
    glutReshapeFunc(ReSizeGLScene);
    glClearColor(0,0,0,0);
    glOrtho(0,400,0,400,50,-50);


speed_rot = glutCreateMenu(speed_menu);
        glutAddMenuEntry("Slow",1);
        glutAddMenuEntry("Medium",2);
        glutAddMenuEntry("Fast",3);
        glutAddMenuEntry("haw",4);
    
 
rotation = glutCreateMenu(rot_menu);
        glutAddMenuEntry("On",1);
        glutAddMenuEntry("Off",2);

colMenu = glutCreateMenu(colors_menu);
        glutAddMenuEntry("Red",1);
        glutAddMenuEntry("Yellow",2);
        glutAddMenuEntry("Blue",3);
        glutAddMenuEntry("Green",4);
rotdirec = glutCreateMenu(direction);
        glutAddMenuEntry("CW",1);
        glutAddMenuEntry("CCW",2);
hawhaw = glutCreateMenu(haw);
        glutAddMenuEntry("haw1",1);
        glutAddMenuEntry("Haw2",2);

    glutCreateMenu(Right_menu);
        glutAddSubMenu("Colors",colMenu);
        glutAddSubMenu("Rotation",rotation);
        glutAddSubMenu("Rotation Speed",speed_rot);
        glutAddSubMenu("The Direction",rotdirec);
        glutAddSubMenu("Hawhawhaw",hawhaw);
        glutAttachMenu(GLUT_RIGHT_BUTTON);


    glutMainLoop();
}