Advertisement
Guest User

Code

a guest
May 26th, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <stdlib.h>
  4. #include "SOIL.h"
  5. #include "glut.h"
  6. #include "freeglut.h"
  7. #include "Obj.h"
  8. using namespace std;
  9.  
  10. Obj* object = new Obj();
  11. GLuint  texture[1];
  12. int w;
  13. int h;
  14.  
  15. void handleResize(int w, int h) {
  16.     glViewport(0, 0, w, h);
  17.     gluPerspective(45.0,(double)w / (double)h,1.0,200.0);
  18. }
  19. void initRendering() {
  20.     object->GetObj("cube.obj");
  21.     glShadeModel(GL_LINEAR);                           
  22.     glClearColor(0.0f, 0.0f, 0.0f, 0.5f);                          
  23.     glEnable(GL_DEPTH_TEST);
  24. }
  25. int LoadGLTextures()
  26. {
  27.     texture[0] = SOIL_load_OGL_texture
  28.         (
  29.         "fehér.png",
  30.         SOIL_LOAD_AUTO,
  31.         SOIL_CREATE_NEW_ID,
  32.         SOIL_FLAG_INVERT_Y
  33.         );
  34.  
  35.     if(texture[0] == 0)
  36.         return false;
  37.  
  38.  
  39.  
  40.     glBindTexture(GL_TEXTURE_2D, texture[0]);
  41.     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  42.     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  43.  
  44.     return true;
  45. }
  46. void handleKeypress(unsigned char key, int x, int y) {
  47.     switch (key) {
  48.         case 27:
  49.             {
  50.             exit(0);
  51.             break;
  52.             }
  53.     }
  54. }
  55.  
  56. void drawScene()
  57. {
  58.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  59.     glMatrixMode(GL_PROJECTION);
  60.     glLoadIdentity();
  61.     glMatrixMode(GL_MODELVIEW);
  62.     glPushMatrix();
  63.     glTranslatef(0.0,0.0,-5.0);
  64.     object->DrawObj();
  65.     glPopMatrix();
  66.     glutSwapBuffers();
  67.     glFlush();
  68.  
  69. }
  70. int _tmain(int argc, char** argv)
  71. {
  72.     glutInit(&argc, argv);
  73.     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  74.     glutInitWindowSize(400, 400);
  75.    
  76.    
  77.     glutCreateWindow("3D");
  78.     initRendering();
  79.    
  80.     glutReshapeFunc(handleResize);
  81.     glutDisplayFunc(drawScene);
  82.     glutKeyboardFunc(handleKeypress);
  83.     glutMainLoop();
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement