GLUT for windows

GLUT

Пример кода (с пошлого занятия)

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

#include <glut.h>

void Init()
{
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_LIGHT0);
  glEnable(GL_LIGHTING);
  glEnable(GL_COLOR_MATERIAL);
}

void Reshape( int wp, int hp )
{
  double r = (double)hp / wp;

  glViewport(0, 0, wp, hp);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glFrustum(-1, 1, -r, r, 1.0, 100.0);
  gluLookAt(10, 0, 3, 0, 0, 0, 0, 0, 1);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
}

void Idle()
{

}

void Display( void )
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glRotated(0.1, 0, 1, 1);
  glColor3d(1, 0, 0);
  glRectd(-2.5, -2.5, 0, 0);
  glColor3d(1, 1, 0);
  glutSolidCube(3);

  glRotated(0.01, 0, 0, 1);

  glPushMatrix();
    glTranslated(0, 4, 0);

    glColor3d(1, 0, 1);
    glutSolidSphere(2, 20, 10);
  glPopMatrix();

  glFinish();
  glutSwapBuffers();

  glutPostRedisplay();
}

void Keyboardsacdscs( unsigned char key, int x, int y )
{
  if (key == 27)
    exit(0);

}

int main( int argc, char** argv )
{
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  glutInitWindowPosition(10, 20);
  glutInitWindowSize(800, 600);
  glutCreateWindow("Ura! LKSH - Forever!");

  Init();
  glutDisplayFunc(Display);
  glutReshapeFunc(Reshape);
  glutKeyboardFunc(Keyboardsacdscs);
  glutIdleFunc(Idle);

  glutMainLoop();
  return 0;
}