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


opengl problems :P by termios
1
 
#include <windows.h>
#include <math.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include "mine.h"


COLOR background;

GLfloat spin = 0.0;



bool init(void) {
    glClearColor(background.r,background.g,background.b,background.a);
    glShadeModel(GL_SMOOTH);
    glClearDepth(10.0);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_ALWAYS);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
    
    

    return true;
}


void reshape(int w,int h) {
    
    glViewport(0,0,(GLsizei)w,(GLsizei)h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    gluPerspective(90.0f,2.0,1.0f,1000.0f);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glTranslatef(0.0,0.0,-1.0);
    


}


void keyboard(unsigned char key,int x,int y) {
    switch(key) {
    case 27:
        exit(0);
        break;
    case 'a':
        if(spin > 0) spin = -spin;
        glutPostRedisplay();
        break;
    case 'd':
        if(spin < 0) spin = -spin;
        glutPostRedisplay();
        break;
    case ' ':
        spin = 1.0;
        break;
    default:
        break;
    }
}

void display(void) {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glRotatef(spin,0.0,1.0,1.0);
    glColor3f(1.0,0.0,0.0);
    glutWireCube(0.5);

    glColor3f(0.0,1.0,0.0);
    
    /*glLineStipple(1,0x0C0F);
    glEnable(GL_LINE_STIPPLE);*/
    
    LINEA(0.3,0.3,-0.3,0.3);
    glutSwapBuffers();
    glFlush();
}


int main(int argc,char **argv) {
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
    glutInitWindowPosition(20,20);
    glutInitWindowSize(500,500);
    glutCreateWindow("Bar");
    background.r = 0.0;
    background.g = 0.1;
    background.b = 0.25;
    background.a = 0.9;
    init();
    glutKeyboardFunc(keyboard);
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutFullScreen();
    glutMainLoop();
    return 0;
}