Professional Documents
Culture Documents
L4
EX.19
#include <GL/glut.h>
#include <windows.h>
#include<math.h>
void def()
{
glClearColor(1,1,1,0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45,1,1,500);
glTranslatef(0,0,-50);
}
void display()
{
def();
glColor3f(1,0,0);
circle(15,15,0,7);
glutSwapBuffers();
glutPostRedisplay();
}
1
مصطفى قيس.م.م
Computer Graphics
L4
2
مصطفى قيس.م.م
Computer Graphics
L4
EX.20
#include <GL/glut.h>
#include <windows.h>
#include<math.h>
void def()
{
glClearColor(1,1,1,0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45,1,1,500);
glTranslatef(0,0,-50);
}
void display()
{
def();
glColor3f(1,0,0);
circle(10,15,0,3.14);
glutSwapBuffers();
glutPostRedisplay();
}
3
مصطفى قيس.م.م
Computer Graphics
L4
4
مصطفى قيس.م.م
Computer Graphics
L4
EX.21
#include <GL/glut.h>
#include <windows.h>
#include<math.h>
#include <stdio.h>
#include <stdlib.h>
void Key(unsigned char key, int x, int y );
void SpecialKeys(int key, int x, int y);
void display(void);
void def()
{
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//gluPerspective(45,1,1,500);
//glTranslatef(0,0,-50);
}
bool keys[255];
float th = 0; /* azimuth of view angle */
float ph = 0; /* elevation of view angle */
GLfloat vertA[3] = { 0.5, 0.5, 0.5};
GLfloat vertB[3] = {-0.5, 0.5, 0.5};
GLfloat vertC[3] = {-0.5,-0.5, 0.5};
GLfloat vertD[3] = { 0.5,-0.5, 0.5};
GLfloat vertE[3] = { 0.5, 0.5,-0.5};
GLfloat vertF[3] = {-0.5, 0.5,-0.5};
GLfloat vertG[3] = {-0.5,-0.5,-0.5};
GLfloat vertH[3] = { 0.5,-0.5,-0.5};
5
مصطفى قيس.م.م
Computer Graphics
L4
void action(void)
{
if(keys[GLUT_KEY_UP])ph += 0.1;
if(keys[GLUT_KEY_DOWN])ph -= 0.1;
if(keys[GLUT_KEY_LEFT])th -= 0.1;
if(keys[GLUT_KEY_RIGHT])th += 0.1;
//th %= 360.0;
//ph %= 360.0;
display();
}
void display()
{
def();
glRotatef(ph,1,0,0);
glRotatef(th,0,1,0);
/* Cube */
glBegin(GL_QUADS);
/* front => ABCD yellow */
glColor3f(1.0,1.0,0.0);
glVertex3fv(vertA);
glVertex3fv(vertB);
glVertex3fv(vertC);
glVertex3fv(vertD);
6
مصطفى قيس.م.م
Computer Graphics
L4
glutSwapBuffers();
glutPostRedisplay();
}
7
مصطفى قيس.م.م
Computer Graphics
L4
8
مصطفى قيس.م.م
Computer Graphics
L4
EX.22
#include <GL/glut.h>
#include <windows.h>
#include<math.h>
#include <stdio.h>
#include <stdlib.h>
void Key(unsigned char key, int x, int y );
void SpecialKeys(int key, int x, int y);
void display(void);
void def()
{
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//gluPerspective(45,1,1,500);
//glTranslatef(0,0,-50);
bool keys[255];
float th = 0; /* azimuth of view angle */
float ph = 0; /* elevation of view angle */
GLfloat vertA[3] = { 0.5, 0.5, 0.5};
GLfloat vertB[3] = {-0.5, 0.5, 0.5};
GLfloat vertC[3] = {-0.5,-0.5, 0.5};
GLfloat vertD[3] = { 0.5,-0.5, 0.5};
GLfloat vertE[3] = { 0.5, 0.5,-0.5};
GLfloat vertF[3] = {-0.5, 0.5,-0.5};
GLfloat vertG[3] = {-0.5,-0.5,-0.5};
GLfloat vertH[3] = { 0.5,-0.5,-0.5};
9
مصطفى قيس.م.م
Computer Graphics
L4
void action(void)
{
if(keys[GLUT_KEY_UP])ph += 0.1;
if(keys[GLUT_KEY_DOWN])ph -= 0.1;
if(keys[GLUT_KEY_LEFT])th -= 0.1;
if(keys[GLUT_KEY_RIGHT])th += 0.1;
//th %= 360.0;
//ph %= 360.0;
display();
}
void display()
{
def();
glRotatef(ph,1,0,0);
glRotatef(th,0,1,0);
/* Cube */
glBegin(GL_LINE_LOOP);
/* front => ABCD yellow */
glColor3f(1.0,1.0,0.0);
10
مصطفى قيس.م.م
Computer Graphics
L4
glVertex3fv(vertA);
glVertex3fv(vertB);
glVertex3fv(vertC);
glVertex3fv(vertD);
/* back => FEHG red */
glColor3f(1.0,0.0,0.0);
glVertex3fv(vertF);
glVertex3fv(vertE);
glVertex3fv(vertH);
glVertex3fv(vertG);
/* right => EADH green */
glColor3f(0.0,1.0,0.0);
glVertex3fv(vertE);
glVertex3fv(vertA);
glVertex3fv(vertD);
glVertex3fv(vertH);
/* left => BFGC blue */
glColor3f(0.0,0.0,1.0);
glVertex3fv(vertB);
glVertex3fv(vertF);
glVertex3fv(vertG);
glVertex3fv(vertC);
/* top => EFBA turquoise */
glColor3f(0.0,1.0,1.0);
glVertex3fv(vertE);
glVertex3fv(vertF);
glVertex3fv(vertB);
glVertex3fv(vertA);
/* bottom => DCGH pink */
glColor3f(1.0,0.0,1.0);
glVertex3fv(vertD);
glVertex3fv(vertC);
glVertex3fv(vertG);
glVertex3fv(vertH);
glEnd();
11
مصطفى قيس.م.م
Computer Graphics
L4
glutSwapBuffers();
glutPostRedisplay();
}
12
مصطفى قيس.م.م
Computer Graphics
L4
EX.23
#include <GL/glut.h>
#include <windows.h>
#include<math.h>
#include <stdio.h>
#include <stdlib.h>
void Key(unsigned char key, int x, int y );
void SpecialKeys(int key, int x, int y);
void display(void);
void def()
{
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45,1,1,500);
glTranslatef(0,0,-50);
}
bool keys[255];
float th = 0; /* azimuth of view angle */
float ph = 0; /* elevation of view angle */
13
مصطفى قيس.م.م
Computer Graphics
L4
void action(void)
{
if(keys[GLUT_KEY_UP])ph += 0.1;
if(keys[GLUT_KEY_DOWN])ph -= 0.1;
if(keys[GLUT_KEY_LEFT])th -= 0.1;
if(keys[GLUT_KEY_RIGHT])th += 0.1;
//th %= 360.0;
//ph %= 360.0;
display();
}
void display()
{
def();
glRotatef(ph,1,0,0);
glRotatef(th,0,1,0);
/* Cube */
glBegin(GL_TRIANGLES);
/* front => ABCD yellow */
glColor3f(1.0,1.0,0.0);
glVertex3f(0.0,10.0,0.0);
glVertex3f(7.0,0.0,7.0);
glVertex3f(-7.0,0.0,7.0);
glColor3f(1.0,0.0,0.0);
glVertex3f(0.0,10.0,0.0);
glVertex3f(7.0,0.0,-7.0);
glVertex3f(-7.0,0.0,-7.0);
glColor3f(0.0,1.0,0.0);
glVertex3f(0.0,10.0,0.0);
glVertex3f(7.0,0.0,7.0);
glVertex3f(7.0,0.0,-7.0);
14
مصطفى قيس.م.م
Computer Graphics
L4
glColor3f(1.0,1.0,1.0);
glVertex3f(0.0,10.0,0.0);
glVertex3f(-7.0,0.0,7.0);
glVertex3f(-7.0,0.0,-7.0);
glEnd();
glutSwapBuffers();
glutPostRedisplay();
}
15
مصطفى قيس.م.م
Computer Graphics
L4
HOME WORK.1
#include <windows.h>
#include <GL/glut.h>
void Display(void)
{
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glBegin(GL_TRIANGLE_FAN);
glColor4f(1,0,0,1);
glVertex3f(0.0, 0.0, 0.0);
glColor4f(0,0,1,1);
glVertex3f(0.5, 0.5, 0.0);
glColor4f(0,1,0,1);
glVertex3f(-0.5, 0.5, 0.0);
glColor4f(0,0,1,1);
glVertex3f(-0.5, -0.5, 0.0);
glColor4f(0,1,0,1);
glVertex3f(0.5,-0.5, 0.0);
glEnd();
glutSwapBuffers();
}
void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize( 500,500);
glutInitWindowPosition (0,0);
glutCreateWindow("OpenGLtest");
glutDisplayFunc(Display);
glutMainLoop();
}
16
مصطفى قيس.م.م
Computer Graphics
L4
Exam.1
#include <windows.h>
#include <GL/glut.h>
void Display(void)
{
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glBegin(GL_TRIANGLES);
glColor4f(1,0,0,1);
glVertex3f(0.0, 0.5, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.3, 0.0, 0.0);
glColor4f(0,0,1,1);
glVertex3f(0.0, 0.5, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(-0.3, 0.0, 0.0);
glEnd();
glutSwapBuffers();
}
void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA |
GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize( 500,500);
glutInitWindowPosition (0,0);
glutCreateWindow("OpenGLtest");
glutDisplayFunc(Display);
glutMainLoop();
}
17
مصطفى قيس.م.م
Computer Graphics
L4
Exam.2
#include <windows.h>
#include <GL/glut.h>
void Display(void)
{
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glBegin(GL_TRIANGLES);
glColor4f(1,0,0,1);
glVertex3f(0.3, 0.3, 0.0);
glVertex3f(0.0, 0.3, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glColor4f(0,0,1,1);
glVertex3f(-0.3, 0.3, 0.0);
glVertex3f(0.0, 0.3, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glEnd();
glutSwapBuffers();
}
void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA |
GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize( 500,500);
glutInitWindowPosition (0,0);
glutCreateWindow("OpenGLtest");
glutDisplayFunc(Display);
glutMainLoop();
}
18
مصطفى قيس.م.م
Computer Graphics
L4
Exam.3
#include <windows.h>
#include <GL/glut.h>
void Display(void)
{
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glBegin(GL_TRIANGLES);
glColor4f(1,0,0,1);
glVertex3f(0.3, -1, 0.0);
glVertex3f(0.0, -1, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glColor4f(0,0,1,1);
glVertex3f(-0.3, -1, 0.0);
glVertex3f(0.0, -1, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glEnd();
glutSwapBuffers();
}
void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA |
GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize( 500,500);
glutInitWindowPosition (0,0);
glutCreateWindow("OpenGLtest");
glutDisplayFunc(Display);
glutMainLoop();
}
19
مصطفى قيس.م.م