Documente Academic
Documente Profesional
Documente Cultură
Efectuat de studentul
grupei IA21: Ghiderman Ion
Chişinău, 2015
1
Condiția laboratorului:
Note teoretice:
2
OpenGL servește două scopuri principale:
3
Listingul programului:
#include <windows.h>
#include "gl.h"
#pragma comment(lib,"opengl32.lib")
#include "glu.h"
#pragma comment(lib,"glu32.lib")
#include "glaux.h"
#pragma comment(lib,"glaux.lib")
#include <math.h>
#define RADGRAD 0.0174532925199433
#define MAXH 150
#define MAXS 150
static GLuint ln;
static GLuint lns[3];
class cone0
{
protected:
int nh;
int ns;
double c[MAXH][MAXS][3];
public:
cone0(int, int);
void drawcon();
};
if(nh>MAXH) nh=MAXH;
else if(nh<1) nh=10;
if(ns>MAXS) ns=MAXS;
else if(ns<3) ns=10;
double hstep=0.35/nh;
double astep=-360./ns;
double hcur,acur,rcur;
hcur=0.0;
double h=0.09;
void cone0::drawcon()
4
{
int i,j;
glBegin(GL_TRIANGLE_FAN);
glVertex3d(0.,0.,0.);
for(j=0; j<ns; j++)
glVertex3dv(c[j][0]);
glVertex3dv(c[0][0]);
glEnd();
void MyLists()
{
glNewList(ln+0,GL_COMPILE);
//Axa x
glBegin(GL_LINES);
glColor3d(0.,0.,0.);
glVertex3d(-5.5,0.,0.);
glColor3d(1.,0.,0.);
glVertex3d(5.5,0.,0.);
glEnd();
glEndList();
glNewList(ln+1,GL_COMPILE);
//Axa y
glBegin(GL_LINES);
glColor3d(0.,0.,0.);
glVertex3d(0.,-5.5,0.);
glColor3d(0.,1.,0.);
glVertex3d(0.,5.5,0.);
glEnd();
glEndList();
glNewList(ln+0,GL_COMPILE);
//Axa z
glBegin(GL_LINES);
glColor3d(0.,0.,0.);
glVertex3d(0.,0.,-5.5);
glColor3d(0.,0.,1.);
glVertex3d(0.,0.,5.5);
glEnd();
glEndList();
}
5
GLuint wp = width<height ? width-20 : height-20;
glViewport(10,10,wp,wp);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
}
double fi=0;
glPushMatrix();
glTranslated(0.,0.,-6.0);
glRotated(35.+fi, 1., 0., 0.);
glRotated(35.+fi, 0., 1., 0.);
fi+=0.09;
glPointSize(10.0f);
glEnable(GL_POINT_SMOOTH);
glBegin(GL_POINTS);
glColor3d(0,0,0);
glVertex3d(0.f,0.f,0.f);
glEnd();
glDisable(GL_POINT_SMOOTH);
glLineWidth(2.0f);
glEnable(GL_LINE_SMOOTH);
glBegin(GL_LINES);
//Axa X
//glCallList(ln+0);
glColor3d(0.,0.,0.);
glVertex3d(-5.5,0.,0.);
glColor3d(1.,0.,0.);
glVertex3d(5.5,0.,0.);
//Axa Y
//glCallList(ln+1);
glColor3d(0.,0.,0.);
glVertex3d(0.,-5.5,0.);
glColor3d(0.,1.,0.);
glVertex3d(0.,5.5,0.);
//Axa Z
//glCallList(ln+2);
glColor3d(0.,0.,0.);
glVertex3d(0.,0.,-5.5);
glColor3d(0.,0.,1.);
glVertex3d(0.,0.,5.5);
glEnd();
//Con X
glColor3d(1,0,0);
glPushMatrix();
glTranslated(5.3f,0.0f,0.0f);
glRotated(90, 0.0f, 1.0f, 0.0f);
auxSolidCone(0.1f,0.2f);
6
glPopMatrix();
//Con Y
glColor3d(0,1,0);
glPushMatrix();
glTranslated(0.0f, 5.3f, 0.0f);
glRotated(-90, 1.0f, 0.0f, 0.0f);
auxSolidCone(0.1f,0.2f);
glPopMatrix();
//Con Z
glColor3d(0,0,1);
glPushMatrix();
glTranslated(0.0f, 0.0f, 5.3f);
auxSolidCone(0.1f,0.2f);
glPopMatrix();
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
//desenarea conurilor
glPushMatrix();
glTranslated(0.0f, 0.0f, 0.0f);
glScaled(2.,2.,5.);
glColor3d(1.,0.,0.);
c1.drawcon();
glPopMatrix();
glPushMatrix();
glTranslated(0.0f, 0.0f, 0.0f);
glScaled(-2.,-2.,5.);
glColor3d(0.,1.,0.);
c1.drawcon();
glPopMatrix();
glPushMatrix();
glTranslated(0.0f, 0.0f, 0.0f);
glScaled(2.,2.,-5.);
glColor3d(0.,0.,1.);
c1.drawcon();
glPopMatrix();
glPushMatrix();
glTranslated(0.0f, 0.0f, 0.0f);
glScaled(-2.,-2.,-5.);
glColor3d(1.,1.,0.);
c1.drawcon();
glPopMatrix();
//desenarea liniilor
for(float i=-1.75; i<0; i+=0.01)
{
glLineWidth(1.3f);
glEnable(GL_LINE_SMOOTH);
glPushMatrix();
glTranslated(0.0f, 0.0f, float(1.75+i));
glRotated(-45.0f, 0.0f, 0.0f, 1.0f);
glBegin(GL_LINES);
glColor3d(1.,0.,1.);
glVertex3d(1.75+i,0.,0.);
7
glColor3d(1.,0.,1.);
glVertex3d(-1.75-i,0.,0.);
glEnd();
glPopMatrix();
}
///////////////////////////////////////////////////////
glColor3d(0.,1.,1.);
glVertex3d(1.75-i,0.,0.);
glColor3d(0.,1.,1.);
glVertex3d(-1.75+i,0.,0.);
glEnd();
glPopMatrix();
}
glPopMatrix();
auxSwapBuffers();
}
void main()
{
auxInitPosition(0,0,500,500);
auxInitDisplayMode(AUX_RGB|AUX_DEPTH|AUX_DOUBLE);
auxInitWindow((LPCWSTR)("OpenGL"));
auxIdleFunc(display);
auxReshapeFunc(resize);
glEnable(GL_ALPHA_TEST);
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
8
auxMainLoop(display);
}
Rezultatul:
Concluzie:
9
În lucrarea dată am folosit bibliotecile OpenGL, care sunt foarte importante
la desenarea diferitor figuri.
10