2044

desenare triunghiuri in OpenGL

#include #include //Needed for "exit" function//Include OpenGL header files, so that we can use OpenGL#include "glut.h"using namespace std;//Called when a key is pressedvoid handleKeypress(unsigned char key, //The key that was pressedint x, int y) { //The current mouse coordinatesswitch (key) {case 27: //Escape keyexit(0); //Exit the program}}//Initializes 3D renderingvoid initRendering() {//Makes 3D drawing work when something is in front of something elseglEnable(GL_DEPTH_TEST);}//Called when the window is resizedvoid handleResize(int w, int h) {//Tell OpenGL how to convert from coordinates to pixel valuesglViewport(0, 0, w, h);glMatrixMode(GL_PROJECTION); //Switch to setting the camera perspective//Set the camera perspectiveglLoadIdentity(); //Reset the cameragluPerspective(45.0, //The camera angle (double)w / (double)h, //The width-to-height ratio 1.0, //The near z clipping coordinate 200.0); //The far z clipping coordinate}//Draws the 3D scenevoid drawScene() {//Clear information from last drawglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspectiveglLoadIdentity(); //Reset the drawing perspectiveglBegin(GL_QUADS); //Begin quadrilateral coordinates//TrapezoidglVertex3f(-0.7f, -1.5f, -5.0f);glVertex3f(0.7f, -1.5f, -5.0f);glVertex3f(0.4f, -0.5f, -5.0f);glVertex3f(-0.4f, -0.5f, -5.0f);glEnd(); //End quadrilateral coordinatesglBegin(GL_TRIANGLES); //Begin triangle coordinates//PentagonglVertex3f(0.5f, 0.5f, -5.0f);glVertex3f(1.5f, 0.5f, -5.0f);glVertex3f(0.5f, 1.0f, -5.0f);glVertex3f(0.5f, 1.0f, -5.0f);glVertex3f(1.5f, 0.5f, -5.0f);glVertex3f(1.5f, 1.0f, -5.0f);glVertex3f(0.5f, 1.0f, -5.0f);glVertex3f(1.5f, 1.0f, -5.0f);glVertex3f(1.0f, 1.5f, -5.0f);//TriangleglVertex3f(-0.5f, 0.5f, -5.0f);glVertex3f(-1.0f, 1.5f, -5.0f);glVertex3f(-1.5f, 0.5f, -5.0f);glEnd(); //End triangle coordinatesglutSwapBuffers(); //Send the 3D scene to the screen}int main(int argc, char** argv) {//Initialize GLUTglutInit(&argc, argv);glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);glutInitWindowSize(400, 400); //Set the window size//Create the windowglutCreateWindow("Basic Shapes - videotutorialsrock.com");initRendering(); //Initialize rendering//Set handler functions for drawing, keypresses, and window resizesglutDisplayFunc(drawScene);glutKeyboardFunc(handleKeypress);glutReshapeFunc(handleResize);glutMainLoop(); //Start the main loop. glutMainLoop doesn't return.return 0; //This line is never reached}biblioteca glut poate fi luata de aici http://www.xmission.com/~nate/glut.html biblioteca/cartea*
0