Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Relevant data structures. */
- struct GPoint_st
- {
- float x, y, z;
- float nx, ny, nz;
- float s0, t0;
- };
- typedef struct GSolid_st
- {
- GPoint* grid;
- int size;
- int gridmode;
- GColor* color;
- struct GSolid_st* next;
- } GSolid;
- //A 4x4 matrix is represented by a 16 cell float array.
- typedef float GOperator;
- /* Some very relevant code concerning the VBO usage:
- */
- void
- gscreen_init(int* argc, char* argv[], void (*render)(void))
- {
- glutInit(argc, argv);
- glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
- glutInitWindowPosition(100, 100);
- glutInitWindowSize(win_width, win_height);
- glutCreateWindow("Pub");
- glutReshapeFunc(&gscreen_reshape);
- glutDisplayFunc(render);
- glutIdleFunc(render);
- glutPassiveMotionFunc(&gmouse_passivemov);
- glutKeyboardFunc(&gkeyboard_keypress);
- glutKeyboardUpFunc(&gkeyboard_keyrelease);
- glutSetKeyRepeat(GLUT_KEY_REPEAT_OFF);
- //TODO: allow camera to be initialized anywhere else.
- gcamera_init(3);
- CAM->cam_eye[0] = 0; CAM->cam_eye[1] = 0; CAM->cam_eye[2] = 0;
- CAM->cam_dir[0] = 0; CAM->cam_dir[1] = 0; CAM->cam_dir[2] = 1;
- if (glewInit() != GLEW_OK)
- {
- fprintf(stderr, "err: glewInit();\n");
- exit(__LINE__);
- }
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_NORMAL_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glGenBuffers(1, buffer);
- }
- static void
- gscreen_default_render()
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- //Let's clear our matrix
- glLoadIdentity();
- //Firstly, we should apply our camera transformations,
- gcamera_apply();
- glClearColor(0.0f,0.0f,0.0f,0.0f);
- // draw the base's front
- glCullFace(GL_BACK);
- // set filling mode
- glPolygonMode(GL_FRONT, GL_FILL);
- //Now, we should render all objects
- //gscreen_object_renderer();
- glutWireTeapot(3.0f);
- //and swap buffers.
- glutSwapBuffers();
- }
- static void
- gscreen_display_solid(GSolid* s, GOperator* op)
- {
- if (!s)
- return;
- glBindBuffer(GL_ARRAY_BUFFER, *buffer);
- glBufferData(GL_ARRAY_BUFFER, s->size*sizeof(GPoint), s->grid, GL_STATIC_DRAW);
- for (int i = 0; i < s->size; i++)
- printf("%.1f %.1f %.1f\n", s->grid[i].x, s->grid[i].y, s->grid[i].z);
- glVertexPointer(3, GL_FLOAT, sizeof(GPoint), 0);
- //glNormalPointer(GL_FLOAT, 8*sizeof(float), (float*)(sizeof(GLfloat)*3));
- if (op)
- {
- glPushMatrix();
- glMultMatrixf(op);
- }
- glDrawArrays(s->gridmode, 0, s->size);
- if (op)
- glPopMatrix();
- gscreen_display_solid(s->next, op);
- }
- void
- gscreen_object_renderer()
- {
- vector<triple<GSolid*, GOperator*, int> >::iterator i;
- for (i=screen_objs.begin(); i < screen_objs.end(); i++)
- {
- if ((*i).c == GSCREEN_OBJECT_DISPLAY)
- gscreen_display_solid((*i).a, (*i).b);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement