Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <math.h>
- #include <stdlib.h>
- #if defined(__APPLE__)
- #include <OpenGL/gl.h>
- #include <OpenGL/glu.h>
- #include <GLUT/glut.h>
- #else
- #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
- #include <windows.h>
- #endif
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <GL/glut.h>
- #endif
- void onDisplay() {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glutSolidSphere(1.0f, 16, 16);
- glutSwapBuffers();
- }
- void onIdle() {
- static bool first_call = true;
- if(first_call) {
- glutPostRedisplay();
- first_call = false;
- }
- }
- void onInitialization() {
- glEnable(GL_DEPTH_TEST);
- glMatrixMode(GL_PROJECTION);
- gluPerspective(60, 1, 0.1, 10);
- glMatrixMode(GL_MODELVIEW);
- gluLookAt(-3, 2, -2, 0, 0, 0, 0, 1, 0);
- glEnable(GL_LIGHTING);
- glEnable(GL_COLOR_MATERIAL);
- glEnable(GL_LIGHT0);
- float p[4] = {-1.1f, 2.0f, -1.2f, 1};
- glLightfv(GL_LIGHT0, GL_POSITION, p);
- float c[4] = {0.7f, 0.8f, 0.9f, 1.0f};
- glLightfv(GL_LIGHT0, GL_DIFFUSE, c);
- glShadeModel(GL_SMOOTH);
- glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.0f);
- glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.5f);
- glFrontFace(GL_CCW);
- glCullFace(GL_BACK);
- glEnable(GL_CULL_FACE);
- }
- void onKeyboard(unsigned char key, int, int) {}
- void onKeyboardUp(unsigned char key, int, int) {}
- void onMouse(int, int, int, int) {}
- void onMouseMotion(int, int) {}
- int main(int argc, char **argv) {
- glutInit(&argc, argv);
- glutInitWindowSize(300, 300);
- glutInitWindowPosition(100, 100);
- glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
- glutCreateWindow("Grafika pelda program");
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- onInitialization();
- glutDisplayFunc(onDisplay);
- glutMouseFunc(onMouse);
- glutIdleFunc(onIdle);
- glutKeyboardFunc(onKeyboard);
- glutKeyboardUpFunc(onKeyboardUp);
- glutMotionFunc(onMouseMotion);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment