This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!

Error#1_relevant_code

By: VictorCacciari on Apr 4th, 2012  |  syntax: C  |  size: 2.74 KB  |  views: 30  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /* Relevant data structures. */
  2. struct GPoint_st
  3. {
  4.         float x, y, z;
  5.         float nx, ny, nz;
  6.         float s0, t0;
  7. };
  8.  
  9. typedef struct GSolid_st
  10. {
  11.         GPoint*                 grid;
  12.         int                     size;
  13.         int                     gridmode;
  14.         GColor*                 color;
  15.         struct GSolid_st*       next;
  16. } GSolid;
  17.  
  18. //A 4x4 matrix is represented by a 16 cell float array.
  19. typedef float GOperator;
  20.  
  21. /* Some very relevant code concerning the VBO usage:
  22. */
  23. void   
  24. gscreen_init(int* argc, char* argv[], void (*render)(void))
  25. {
  26.         glutInit(argc, argv);
  27.         glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
  28.         glutInitWindowPosition(100, 100);
  29.         glutInitWindowSize(win_width, win_height);
  30.         glutCreateWindow("Pub");
  31.        
  32.         glutReshapeFunc(&gscreen_reshape);
  33.         glutDisplayFunc(render);
  34.         glutIdleFunc(render);
  35.        
  36.         glutPassiveMotionFunc(&gmouse_passivemov);
  37.         glutKeyboardFunc(&gkeyboard_keypress);
  38.         glutKeyboardUpFunc(&gkeyboard_keyrelease);
  39.         glutSetKeyRepeat(GLUT_KEY_REPEAT_OFF);
  40.        
  41.         //TODO: allow camera to be initialized anywhere else.
  42.         gcamera_init(3);
  43.         CAM->cam_eye[0] = 0; CAM->cam_eye[1] = 0; CAM->cam_eye[2] = 0;
  44.         CAM->cam_dir[0] = 0; CAM->cam_dir[1] = 0; CAM->cam_dir[2] = 1;
  45.        
  46.         if (glewInit() != GLEW_OK)
  47.         {
  48.                 fprintf(stderr, "err: glewInit();\n");
  49.                 exit(__LINE__);
  50.         }
  51.        
  52.         glEnableClientState(GL_VERTEX_ARRAY);
  53.         glEnableClientState(GL_NORMAL_ARRAY);
  54.         glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  55.        
  56.         glGenBuffers(1, buffer);
  57. }
  58.  
  59. static void
  60. gscreen_default_render()
  61. {      
  62.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  63.  
  64.         //Let's clear our matrix
  65.         glLoadIdentity();
  66.        
  67.         //Firstly, we should apply our camera transformations,
  68.         gcamera_apply();
  69.        
  70.         glClearColor(0.0f,0.0f,0.0f,0.0f);
  71.        
  72.         // draw the base's front
  73.         glCullFace(GL_BACK);
  74.        
  75.         // set filling mode
  76.         glPolygonMode(GL_FRONT, GL_FILL);
  77.        
  78.         //Now, we should render all objects
  79.         //gscreen_object_renderer();
  80.         glutWireTeapot(3.0f);
  81.         //and swap buffers.
  82.         glutSwapBuffers();
  83. }
  84.  
  85. static void    
  86. gscreen_display_solid(GSolid* s, GOperator* op)
  87. {
  88.         if (!s)
  89.                 return;
  90.                
  91.         glBindBuffer(GL_ARRAY_BUFFER, *buffer);
  92.         glBufferData(GL_ARRAY_BUFFER, s->size*sizeof(GPoint), s->grid, GL_STATIC_DRAW);
  93.         for (int i = 0; i < s->size; i++)
  94.                 printf("%.1f %.1f %.1f\n", s->grid[i].x, s->grid[i].y, s->grid[i].z);
  95.         glVertexPointer(3, GL_FLOAT, sizeof(GPoint), 0);
  96.         //glNormalPointer(GL_FLOAT, 8*sizeof(float), (float*)(sizeof(GLfloat)*3));
  97.        
  98.         if (op)
  99.         {
  100.                 glPushMatrix();
  101.                 glMultMatrixf(op);
  102.         }
  103.        
  104.         glDrawArrays(s->gridmode, 0, s->size);
  105.        
  106.         if (op)
  107.                 glPopMatrix();
  108.                
  109.         gscreen_display_solid(s->next, op);
  110. }
  111.  
  112. void
  113. gscreen_object_renderer()
  114. {
  115. vector<triple<GSolid*, GOperator*, int> >::iterator i;
  116.  
  117.         for (i=screen_objs.begin(); i < screen_objs.end(); i++)
  118.         {
  119.                 if ((*i).c == GSCREEN_OBJECT_DISPLAY)
  120.                         gscreen_display_solid((*i).a, (*i).b);
  121.         }
  122. }
clone this paste RAW Paste Data