kemkriszt

opengl

Apr 3rd, 2014
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. #include "app.h"
  2. #include <gl/glut.h>
  3.  
  4.  
  5. int glutWindowID;
  6.  
  7. bool MyInit(int,char* []);
  8. void MyExit(void);
  9. void MyRender(void);
  10.  
  11. int main(int arg, char* args[]){
  12.     bool isInitialized = MyInit(arg,args);
  13.     if (!isInitialized) {
  14.         return false;
  15.     }
  16.     return 0;
  17. }
  18.  
  19. bool MyInit(int arg,char* args[]){
  20.     glutInit(&arg,args);
  21.     glutInitWindowPosition(-1,-1);
  22.     glutInitWindowSize(600,600);
  23.  
  24.     glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB);
  25.     glutWindowID = glutCreateWindow("Hello");
  26.     glutSetWindow(glutWindowID);
  27.  
  28.     //callback methods
  29.     glutDisplayFunc(MyRender);
  30.     return true;
  31. }
  32.  
  33. void MyExit(void){
  34.     glutDestroyWindow(glutWindowID);
  35. }
  36.  
  37. void MyRender(void){
  38.     //HWND Wnd;
  39.     glutSetWindow(glutWindowID);
  40.     //HDC hDC = GetDC(Wnd);
  41.  
  42.     glClearColor(0.0,0.0,0.9,0.0);
  43.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  44.     glDrawBuffer(GL_BACK);
  45.     glEnable(GL_DEPTH_TEST);
  46.     glEnable(GL_LIGHTING);
  47.  
  48.     //lighting
  49.     float Mambient[]={0.2,0.2,0.2,1.0};
  50.     glLightModelfv(GL_LIGHT_MODEL_AMBIENT,Mambient);
  51.  
  52.     float LightAmbient[] = {0.1,0.1,0.1,1.0};
  53.     float LightDiffuse[] = {0.5,0.5,0.5,1.0};
  54.     float LightPosition[] = {5.0,5.0,5.0,0.0};
  55.     glLightfv(GL_LIGHT0,GL_AMBIENT,LightAmbient);
  56.     glLightfv(GL_LIGHT0,GL_DIFFUSE,LightDiffuse);
  57.     glLightfv(GL_LIGHT0,GL_POSITION,LightPosition);
  58.     glEnable(GL_LIGHT0);
  59.  
  60.     /*RECT rect;
  61.     GetClientRect(Wnd, &rect);
  62.     float width = rect.right - rect.left;
  63.     float height = rect.bottom - rect.top;
  64.     float aspect = (height == 0)?width:width/height;
  65.     glViewport(0,0,width,height);
  66.     glMatrixMode(GL_PROJECTION);
  67.     glLoadIdentity();
  68.     gluPerspective(45,aspect,1,100);*/
  69.  
  70.     glMatrixMode(GL_MODELVIEW);
  71.     glLoadIdentity();
  72.     gluLookAt(2.0,3.0,4.0,0.0,0.0,0.0,0.0,1.0,0.0);
  73.  
  74.     float GreenS[] = {1.0,0.0,0.0,1.0};
  75.     glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,GreenS);
  76.     glutSolidTeapot(1.0);
  77.  
  78.     glutSwapBuffers();
  79. }
Advertisement
Add Comment
Please, Sign In to add comment