// draw callback // Purposes: // - Load the navigation matrix to reflect frame's navigation // - Use OpenGL to generate computer graphics. void draw(arMasterSlaveFramework& framework) { // Load the navigation matrix. framework.loadNavMatrix(); // Generate graphics. if(selectionMode == 2) { renderPrimitive(-2.5f); // draws square with quadrants drawObjects(-2.5f); // draw the mini versions } vector<arInteractable*>::iterator i; for(i=objects.begin(); i != objects.end(); ++i) { Object* oby = ((Object*)(*i)); oby->draw(); } // Draw the effectors. rightHand.draw(); leftHand.draw(); }
/* Function: Runs the application display Flow: - Check key operations as they may have adverse effects on the display state e.g may require the display matrix to move forward - Set Clear color ( RED in this case ) - Clear the color buffer ( Using GL_COLOR_BUFFER_BIT ) information in other buffers will come later - Load the Identity Matrix ( Poorly named me thinks ) to reset our drawing locations - Move the camera to look in the required direction - Render object to screen ( Will render at location: 0, 0, -5 ) - Swap buffers - Calcualte transofrmations for object End State: Rendering of picture to the the window of the application */ void display(void) { /* Check any keyboard operations that may alter the display of the next frame */ keyOperations(); keySpecialOperations(); // Clear color is set to RED glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Clear the color buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); // Set lights up GLfloat DiffuseLight[] = { diffuseLightRed, diffuseLightGreen, diffuseLightBlue }; GLfloat AmbientLight[] = { ambientLightRed, ambientLightGreen, ambientLightBlue }; glLightfv (GL_LIGHT0, GL_DIFFUSE, DiffuseLight); //change the light accordingly glLightfv (GL_LIGHT1, GL_AMBIENT, AmbientLight); //change the light accordingly // Set light position GLfloat LightPosition[] = {lightX, lightY, lightZ, lightW}; // lightW indicates if it is a point light glLightfv (GL_LIGHT0, GL_POSITION, LightPosition); //change the light accordingly // Reset Identity Matrix //glLoadIdentity(); // Light the scene //light(); // Look at a point gluLookAt (ViewPositionX, ViewPositionY, ViewPositionZ - 10.0, ViewPositionX, ViewPositionY, ViewPositionZ, 0.0, 1.0, 0.0); // Render objects renderPrimitive(); // Swap the old buffer out for the new rendered image glutSwapBuffers(); // Increase angle angle += 0.1; }
void mergeFaceRender(world::chunk* c) { int cx = c->cx, cy = c->cy, cz = c->cz; int x = 0, y = 0, z = 0; QuadPrimitive cur; int cur_l_mx; block bl, neighbour; brightness br; bool valid = false; for (int steps = 0; steps < 3; steps++) { cur = QuadPrimitive(); cur_l_mx = bl = neighbour = br = 0; //Linear merge renderer::Init(3, 3); for (int d = 0; d < 6; d++){ cur.direction = d; for (int i = 0; i < 16; i++) for (int j = 0; j < 16; j++) { for (int k = 0; k < 16; k++) { //Get position if (d < 2) x = i, y = j, z = k; else if (d < 4) x = i, y = j, z = k; else x = k, y = i, z = j; //Get properties bl = c->getblock(x, y, z); //Get neighbour properties int xx = x + delta[d][0], yy = y + delta[d][1], zz = z + delta[d][2]; int gx = cx * 16 + xx, gy = cy * 16 + yy, gz = cz * 16 + zz; if (xx < 0 || xx >= 16 || yy < 0 || yy >= 16 || zz < 0 || zz >= 16) { neighbour = world::getblock(gx, gy, gz); br = world::getbrightness(gx, gy, gz); } else { neighbour = c->getblock(xx, yy, zz); br = c->getbrightness(xx, yy, zz); } //Render if (bl == blocks::AIR || bl == neighbour && bl != blocks::LEAF || BlockInfo(neighbour).isOpaque() || steps == 0 && BlockInfo(bl).isTranslucent() || steps == 1 && (!BlockInfo(bl).isTranslucent() || !BlockInfo(bl).isSolid()) || steps == 2 && (!BlockInfo(bl).isTranslucent() || BlockInfo(bl).isSolid())) { //Not valid block if (valid) { if (BlockInfo(neighbour).isOpaque()) { if (cur_l_mx < cur.length) cur_l_mx = cur.length; cur_l_mx++; } else { renderPrimitive(cur); valid = false; } } continue; } if (valid) { if (bl != cur.block || br != cur.brightness) { renderPrimitive(cur); cur.x = x; cur.y = y; cur.z = z; cur.length = cur_l_mx = 0; cur.block = bl; cur.brightness = br; } else { if (cur_l_mx > cur.length) cur.length = cur_l_mx; cur.length++; } } else { valid = true; cur.x = x; cur.y = y; cur.z = z; cur.length = cur_l_mx = 0; cur.block = bl; cur.brightness = br; } } if (valid) { renderPrimitive(cur); valid = false; } } } renderer::Flush(c->vbuffer[steps], c->vertexes[steps]); } }