Dear Students,
please send the Questionnaire & and interviews on the following e-mail :
neven.elsaid@gmail.com
Eng. Neven El Said
Friday, 10 April 2009
Light
#include
//Initializes 3D rendering
void initRendering() {
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING); //Enable lighting
glEnable(GL_LIGHT0); //Enable light #0
glEnable(GL_LIGHT1); //Enable light #1
glEnable(GL_NORMALIZE); //Automatically normalize normals
}
void handleResize(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (double)w / (double)h, 1.0, 200.0);
}
float angle = -70.0f;
//Draws the 3D scene
void drawScene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//Add positioned light
GLfloat lightColor0[] = {0.5f, 0.5f, 0.5f, 1.0f}; //Color (0.5, 0.5, 0.5)
GLfloat lightPos0[] = {4.0f, 0.0f, 8.0f, 1.0f}; //Positioned at (4, 0, 8) & 1.0 means Positioned
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0); //assign the intenisty of light0
glLightfv(GL_LIGHT0, GL_POSITION, lightPos0); // put the light0 at the postion in the position array
//Add directed light
GLfloat lightColor1[] = {0.5f, 0.2f, 0.2f, 1.0f}; //Color (0.5, 0.2, 0.2)
GLfloat lightPos1[] = {-1.0f, 0.5f, 0.5f, 0.0f}; //Coming from the direction (-1, 0.5, 0.5) & 0.0 means Directioned
glLightfv(GL_LIGHT1, GL_DIFFUSE, lightColor1); //assign the intenisty of light1
glLightfv(GL_LIGHT1, GL_POSITION, lightPos1); // put the light0 at the postion in the position array
glRotatef(angle, 0.0f, 1.0f, 0.0f);
glColor3f(1.0f, 1.0f, 0.0f);
glBegin(GL_QUADS);
//Front
glNormal3f(0.0f, 0.0f, 1.0f); // normal to the x,y Plan (+ve direction of z)
glVertex3f(-1.5f, -1.0f, 1.5f);
glVertex3f(1.5f, -1.0f, 1.5f);
glVertex3f(1.5f, 1.0f, 1.5f);
glVertex3f(-1.5f, 1.0f, 1.5f);
//Right
glNormal3f(1.0f, 0.0f, 0.0f); // normal to the y,z Plan (+ve direction of x)
glVertex3f(1.5f, -1.0f, -1.5f);
glVertex3f(1.5f, 1.0f, -1.5f);
glVertex3f(1.5f, 1.0f, 1.5f);
glVertex3f(1.5f, -1.0f, 1.5f);
//Back
glNormal3f(0.0f, 0.0f, -1.0f); // normal to the x,y Plan (-ve direction of z)
glVertex3f(-1.5f, -1.0f, -1.5f);
glVertex3f(-1.5f, 1.0f, -1.5f);
glVertex3f(1.5f, 1.0f, -1.5f);
glVertex3f(1.5f, -1.0f, -1.5f);
//Left
glNormal3f(-1.0f, 0.0f, 0.0f); // normal to the y,z Plan (-ve direction of x)
glVertex3f(-1.5f, -1.0f, -1.5f);
glVertex3f(-1.5f, -1.0f, 1.5f);
glVertex3f(-1.5f, 1.0f, 1.5f);
glVertex3f(-1.5f, 1.0f, -1.5f);
glEnd();
glutSwapBuffers();
}
void update(int value) {
angle += 1.5f;
if (angle > 360) {
angle -= 360;
}
glutPostRedisplay();
glutTimerFunc(25, update, 0);
}
int main(int argc, char** argv) {
//Initialize GLUT
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800, 600);
//Create the window
glutCreateWindow("Lighting");
initRendering();
//Set handler functions
glutDisplayFunc(drawScene);
glutReshapeFunc(handleResize);
glutTimerFunc(25, update, 0); //Add a timer
glutMainLoop();
return 0;
}
//Initializes 3D rendering
void initRendering() {
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING); //Enable lighting
glEnable(GL_LIGHT0); //Enable light #0
glEnable(GL_LIGHT1); //Enable light #1
glEnable(GL_NORMALIZE); //Automatically normalize normals
}
void handleResize(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (double)w / (double)h, 1.0, 200.0);
}
float angle = -70.0f;
//Draws the 3D scene
void drawScene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//Add positioned light
GLfloat lightColor0[] = {0.5f, 0.5f, 0.5f, 1.0f}; //Color (0.5, 0.5, 0.5)
GLfloat lightPos0[] = {4.0f, 0.0f, 8.0f, 1.0f}; //Positioned at (4, 0, 8) & 1.0 means Positioned
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0); //assign the intenisty of light0
glLightfv(GL_LIGHT0, GL_POSITION, lightPos0); // put the light0 at the postion in the position array
//Add directed light
GLfloat lightColor1[] = {0.5f, 0.2f, 0.2f, 1.0f}; //Color (0.5, 0.2, 0.2)
GLfloat lightPos1[] = {-1.0f, 0.5f, 0.5f, 0.0f}; //Coming from the direction (-1, 0.5, 0.5) & 0.0 means Directioned
glLightfv(GL_LIGHT1, GL_DIFFUSE, lightColor1); //assign the intenisty of light1
glLightfv(GL_LIGHT1, GL_POSITION, lightPos1); // put the light0 at the postion in the position array
glRotatef(angle, 0.0f, 1.0f, 0.0f);
glColor3f(1.0f, 1.0f, 0.0f);
glBegin(GL_QUADS);
//Front
glNormal3f(0.0f, 0.0f, 1.0f); // normal to the x,y Plan (+ve direction of z)
glVertex3f(-1.5f, -1.0f, 1.5f);
glVertex3f(1.5f, -1.0f, 1.5f);
glVertex3f(1.5f, 1.0f, 1.5f);
glVertex3f(-1.5f, 1.0f, 1.5f);
//Right
glNormal3f(1.0f, 0.0f, 0.0f); // normal to the y,z Plan (+ve direction of x)
glVertex3f(1.5f, -1.0f, -1.5f);
glVertex3f(1.5f, 1.0f, -1.5f);
glVertex3f(1.5f, 1.0f, 1.5f);
glVertex3f(1.5f, -1.0f, 1.5f);
//Back
glNormal3f(0.0f, 0.0f, -1.0f); // normal to the x,y Plan (-ve direction of z)
glVertex3f(-1.5f, -1.0f, -1.5f);
glVertex3f(-1.5f, 1.0f, -1.5f);
glVertex3f(1.5f, 1.0f, -1.5f);
glVertex3f(1.5f, -1.0f, -1.5f);
//Left
glNormal3f(-1.0f, 0.0f, 0.0f); // normal to the y,z Plan (-ve direction of x)
glVertex3f(-1.5f, -1.0f, -1.5f);
glVertex3f(-1.5f, -1.0f, 1.5f);
glVertex3f(-1.5f, 1.0f, 1.5f);
glVertex3f(-1.5f, 1.0f, -1.5f);
glEnd();
glutSwapBuffers();
}
void update(int value) {
angle += 1.5f;
if (angle > 360) {
angle -= 360;
}
glutPostRedisplay();
glutTimerFunc(25, update, 0);
}
int main(int argc, char** argv) {
//Initialize GLUT
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800, 600);
//Create the window
glutCreateWindow("Lighting");
initRendering();
//Set handler functions
glutDisplayFunc(drawScene);
glutReshapeFunc(handleResize);
glutTimerFunc(25, update, 0); //Add a timer
glutMainLoop();
return 0;
}
Wednesday, 8 April 2009
rotation in different direction in the same scene
glPushMatrix(); //Save the rotation for the Quad
glRotatef(angle, 0.0f, 0.0f, 1.0f); //Rotate about the z-axis
glBegin(GL_QUADS);
glVertex3f(-0.7f, -0.5f, 0.0f);
glVertex3f(0.7f, -0.5f, 0.0f);
glVertex3f(0.4f, 0.5f, 0.0f);
glVertex3f(-0.4f, 0.5f, 0.0f);
glEnd();
glPopMatrix(); //Undo the rotation
glPushMatrix(); //Save the new rotation for the triangle
glRotatef(angle, 0.0f, 1.0f, 0.0f); //Rotate about the y-axis
glBegin(GL_TRIANGLES);
glVertex3f(-0.5f, -0.5f, 0.0f);
glVertex3f(0.5f, -0.5f, 0.0f);
glVertex3f(-0.5f, 0.0f, 0.0f);
glEnd();
glPopMatrix(); //Undo the rotation of the triangle
glRotatef(angle, 0.0f, 0.0f, 1.0f); //Rotate about the z-axis
glBegin(GL_QUADS);
glVertex3f(-0.7f, -0.5f, 0.0f);
glVertex3f(0.7f, -0.5f, 0.0f);
glVertex3f(0.4f, 0.5f, 0.0f);
glVertex3f(-0.4f, 0.5f, 0.0f);
glEnd();
glPopMatrix(); //Undo the rotation
glPushMatrix(); //Save the new rotation for the triangle
glRotatef(angle, 0.0f, 1.0f, 0.0f); //Rotate about the y-axis
glBegin(GL_TRIANGLES);
glVertex3f(-0.5f, -0.5f, 0.0f);
glVertex3f(0.5f, -0.5f, 0.0f);
glVertex3f(-0.5f, 0.0f, 0.0f);
glEnd();
glPopMatrix(); //Undo the rotation of the triangle
Thursday, 26 March 2009
Computer Graphics Lab 1 ( program 1)
#include //include the GLUT library responsible for the window, menus....etc
#include //include the GL library responsible for the drawing function
void Init(void) // Your initialization function and its Name is not a constant u change it
{
glClearColor(1.0,1.0,1.0,0.0); //set the background color
glMatrixMode(GL_PROJECTION); // set the Matrix Mode with the projection Mode
gluOrtho2D(0.0,200.0,0.0,150.0); // set the range of the view orthogonal
glPointSize(4.0); // set the one point =4 pixels
}
void Linesg(void)
{
glClear(GL_COLOR_BUFFER_BIT); // load the bg color from the COLOR BUFFER BIT
glColor3f(1.0,0.0,0.0); // set the drawing color with RED color
glBegin(GL_LINE_STRIP); //Begin Drawing Line Strip
glVertex2i(10,10); //p1 where 2i = 2 arguments (x, y) & i for integer
glVertex2i(10,50); // p2
glVertex2i(150,10); // p3
glVertex2i(150,50); // p4
glEnd(); //end of drawing function
glFlush(); // flush the scene from the buffer to show on the screen
}
void main/(int argc,char** argv) // main C++ function
{
glutInit (&argc,argv); // initialize the toolkit
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); // use Single buffer & RGB color mode
glutInitWindowPosition(50,100); // set the window position @ 50 x & 100 y
glutInitWindowSize(400,300); // set the window size 400 width & 300 height
glutCreateWindow(" This is my first Example"); // create the window with title "This i...."
Init(); // call ur initialization function
glutDisplayFunc(Linesg); // call ur display function
glutMainLoop(); // call the Main loop of the openGL which keep waiting
//for keyboard or mouse events
}
#include //include the GL library responsible for the drawing function
void Init(void) // Your initialization function and its Name is not a constant u change it
{
glClearColor(1.0,1.0,1.0,0.0); //set the background color
glMatrixMode(GL_PROJECTION); // set the Matrix Mode with the projection Mode
gluOrtho2D(0.0,200.0,0.0,150.0); // set the range of the view orthogonal
glPointSize(4.0); // set the one point =4 pixels
}
void Linesg(void)
{
glClear(GL_COLOR_BUFFER_BIT); // load the bg color from the COLOR BUFFER BIT
glColor3f(1.0,0.0,0.0); // set the drawing color with RED color
glBegin(GL_LINE_STRIP); //Begin Drawing Line Strip
glVertex2i(10,10); //p1 where 2i = 2 arguments (x, y) & i for integer
glVertex2i(10,50); // p2
glVertex2i(150,10); // p3
glVertex2i(150,50); // p4
glEnd(); //end of drawing function
glFlush(); // flush the scene from the buffer to show on the screen
}
void main/(int argc,char** argv) // main C++ function
{
glutInit (&argc,argv); // initialize the toolkit
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); // use Single buffer & RGB color mode
glutInitWindowPosition(50,100); // set the window position @ 50 x & 100 y
glutInitWindowSize(400,300); // set the window size 400 width & 300 height
glutCreateWindow(" This is my first Example"); // create the window with title "This i...."
Init(); // call ur initialization function
glutDisplayFunc(Linesg); // call ur display function
glutMainLoop(); // call the Main loop of the openGL which keep waiting
//for keyboard or mouse events
}
FCI Computer Graphics
Dear All,
Hope all is fine...
according to the rich resources on the internet for computer graphics I made this blog to share these resources with u all,
& and also to follow ur project progress
Thanks,
Eng. Neven El Said
Hope all is fine...
according to the rich resources on the internet for computer graphics I made this blog to share these resources with u all,
& and also to follow ur project progress
Thanks,
Eng. Neven El Said
Subscribe to:
Comments (Atom)