Thursday, January 17, 2008

Assignment 2: Amplifier

This is one of the model that i wanted to put in my skybox. It will be together with my guitar along with another model that i have yet to create.


This modelling is created using the Maya software.


Wednesday, December 12, 2007

Week 9: Assignment 1



Now this is my complete version of assignment 1. I modelled a bass guitar based on the above picture taken.


So this is my model..
Plotting on a graph paper with the x and y axis before startin doing it on openGL really helps alot with the visualisation. So alot of time is saved and the job is easily done.

Week 8: Assignment 1

I actually started off with an alien. Here's how it goes.

After doing halfway, I have to redo. I won't even dare to hand it in. It looks too lousy to pass. So practically this is just a practise to start off with.

Wednesday, November 28, 2007

Practical 7


#include "glut.h"
GLfloat angle= 0.0f;
GLfloat width= 40.0f;
GLfloat height= 30.0f;
int x=0;
int y=0;
void init(void)
{
GLfloat ambient[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat position[] = { 0.0, 3.0, 2.0, 0.0 };
GLfloat lmodel_ambient[] = { 0.4, 0.4, 0.4, 1.0 };
glClearColor(0.0, 0.1, 0.1, 0.0);
//Enable Depth test

glShadeModel(GL_SMOOTH);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, position);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}

void MyDisplay()
{
GLfloat mat_diffuse[] = { 0.1, 0.5, 0.8, 1.0 };
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat low_shininess[] = { 5.0 };
//Clear buffer.
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess);

GLUquadricObj *Cylinder;
GLUquadricObj *Disk;
glEnable(GL_DEPTH);
glClear(GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT);
Cylinder = gluNewQuadric();
Disk = gluNewQuadric();
gluQuadricDrawStyle(Cylinder, GLU_FILL);
//glLoadIdentity();
glPopMatrix();

glBegin(GL_LINES);
glColor3f(1,1,1);
glVertex3f(0,0,0);
glVertex3f(400,0,0);
glVertex3f(0,0,0);
glVertex3f(0,400,0);
glVertex3f(0,0,0);
glVertex3f(0,0,400);
glEnd();

glPushMatrix();
glTranslatef(::x,y,0);
glColor3f(1,0,0);
gluCylinder(Cylinder,15,15,40,32,32);
glColor3f(0,1,0);
gluDisk(Disk,0.5,1.5,32,32);
glEnd();

glutSwapBuffers();
}

// Called by GLUT library when the window has changed size

void Rescale(GLsizei w, GLsizei h)
{
glViewport(0,0,w,h);
}

void SetupRC()
{
GLfloat final = width / height;
gluPerspective(90, final , 0, 1000);
gluLookAt(90,90,90,0,1,0,0,1,0);
glFlush();
glPushMatrix();
}

void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE GLUT_RGB GLUT_DEPTH);
glutInitWindowSize(640, 480);
glutCreateWindow("My Practical 7");
glutDisplayFunc(MyDisplay);
init();
glutReshapeFunc(Rescale);
SetupRC();
glutMainLoop();
}

Practical 6



#include "glut.h"

GLfloat angle= 0.0f;
GLfloat width= 40.0f;
GLfloat height= 30.0f;
int x=0;
int y=0;
int z=0;

void drawBody()
{
glColor3f(0,0,1);
glBegin(GL_QUADS);
glVertex3f(-15,5,0);
glVertex3f(15,5,0);
glVertex3f(15,-20,0);
glVertex3f(-15,-20,0);
glEnd();

glColor3f(0,0,1);
glBegin(GL_QUADS);
glVertex3f(-15,5,10);
glVertex3f(15,5,10);
glVertex3f(15,-20,10);
glVertex3f(-15,-20,10);
glEnd();

glColor3f(0,0,1);
glBegin(GL_QUADS);
glVertex3f(15,5,10);
glVertex3f(15,5,0);
glVertex3f(15,-20,0);
glVertex3f(15,-20,10);
glEnd();

glColor3f(0,0,1);
glBegin(GL_QUADS);
glVertex3f(-15,5,10);
glVertex3f(-15,5,0);
glVertex3f(-15,-20,0);
glVertex3f(-15,-20,10);
glEnd();

glColor3f(0,0,1);
glBegin(GL_QUADS);
glVertex3f(-15,5,0);
glVertex3f(15,5,0);
glVertex3f(15,5,10);
glVertex3f(-15,5,10);
glEnd();

glColor3f(0,0,1);
glBegin(GL_QUADS);
glVertex3f(-15,-20,0);
glVertex3f(15,-20,0);
glVertex3f(15,-20,10);
glVertex3f(-15,-20,10);
glEnd();
}

void drawLimb()
{
glColor3f(1,0,0);
glBegin(GL_QUADS);
glVertex3f(-5,5,8);
glVertex3f(1,5,8);
glVertex3f(1,-15,8);
glVertex3f(-5,-15,8);
glEnd();

glColor3f(1,0,0);
glBegin(GL_QUADS);
glVertex3f(-5,5,2);
glVertex3f(1,5,2);
glVertex3f(1,-15,2);
glVertex3f(-5,-15,2);
glEnd();

glColor3f(1,0,0);
glBegin(GL_QUADS);
glVertex3f(1,5,8);
glVertex3f(1,5,2);
glVertex3f(1,-15,2);
glVertex3f(1,-15,8);
glEnd();

glColor3f(1,0,0);
glBegin(GL_QUADS);
glVertex3f(-5,5,8);
glVertex3f(-5,5,2);
glVertex3f(-5,-15,2);
glVertex3f(-5,-15,8);
glEnd();

glColor3f(1,0,0);
glBegin(GL_QUADS);
glVertex3f(-5,5,2);
glVertex3f(1,5,2);
glVertex3f(1,5,8);
glVertex3f(-5,5,8);
glEnd();

glColor3f(1,0,0);
glBegin(GL_QUADS);
glVertex3f(-5,-15,2);
glVertex3f(1,-15,2);
glVertex3f(1,-15,8);
glVertex3f(-5,-15,8);
glEnd();
}

void drawLimb2()
{
glColor3f(1,1,0);
glBegin(GL_QUADS);
glVertex3f(-5,5,10);
glVertex3f(5,5,10);
glVertex3f(5,-15,10);
glVertex3f(-5,-15,10);
glEnd();

glColor3f(1,1,0);
glBegin(GL_QUADS);
glVertex3f(-5,5,0);
glVertex3f(5,5,0);
glVertex3f(5,-15,0);
glVertex3f(-5,-15,0);
glEnd();

glColor3f(1,1,0);
glBegin(GL_QUADS);
glVertex3f(5,5,10);
glVertex3f(5,5,0);
glVertex3f(5,-15,0);
glVertex3f(5,-15,10);
glEnd();

glColor3f(1,1,0);
glBegin(GL_QUADS);
glVertex3f(-5,5,10);
glVertex3f(-5,5,0);
glVertex3f(-5,-15,0);
glVertex3f(-5,-15,10);
glEnd();

glColor3f(1,1,0);
glBegin(GL_QUADS);
glVertex3f(-5,5,0);
glVertex3f(5,5,0);
glVertex3f(5,5,10);
glVertex3f(-5,5,10);
glEnd();

glColor3f(1,1,0);
glBegin(GL_QUADS);
glVertex3f(-5,-15,0);
glVertex3f(5,-15,0);
glVertex3f(5,-15,10);
glVertex3f(-5,-15,10);
glEnd();
}

void drawHead()
{
glColor3f(1,0,1);
glutSolidSphere(9.5,36,25);
}

void MyDisplay()
{
glClear(GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT);
//glLoadIdentity();

glEnable(GL_DEPTH);
glPopMatrix();
glBegin(GL_LINES);
glColor3f(1,1,1);
glVertex3f(0,0,0);
glVertex3f(400,0,0);
glVertex3f(0,0,0);
glVertex3f(0,400,0);
glVertex3f(0,0,0);
glVertex3f(0,0,400);
glEnd();

glPushMatrix();
glTranslatef(::x,y,z);
glPushMatrix();
glTranslatef(-15, 0.0, 0.0);
drawLimb();
glPopMatrix();
glPushMatrix();
glTranslatef(-20, -15.0, 13);
glRotatef(90.0, 1.0, 0.0, 0.0);
drawLimb();
glPopMatrix();

glPushMatrix();
glTranslatef(-40, -60, -25);
drawLimb2();
glPopMatrix();
glPushMatrix();
glTranslatef(-15, -60, -25);
drawLimb2();
glPopMatrix();
glPushMatrix();
drawBody();
glPopMatrix();

glPushMatrix();
glTranslatef(20, 0.0, 0.0);
drawLimb();
glPopMatrix();
glPushMatrix();
glTranslatef(10, -14.0, 3);
glRotatef(50.0, 1.0, 0.0, 0.0);
drawLimb();
glPopMatrix();
glPushMatrix();
glTranslatef(-17, -5, -12);
drawHead();
glPopMatrix();
glutPostRedisplay();
glutSwapBuffers();
}

void Rescale(GLsizei w, GLsizei h)
{
glViewport(0,0,w,h);
}

void SetupRC()
{
GLfloat final = width / height;
glFrontFace(GL_CCW);
gluPerspective(50, final , 0, 1000);
gluLookAt(90,90,90,0,1,0,0,1,0);
glFlush();
}

void Keyboard(unsigned char key, int x, int y)
{
switch(key) //check which key is pressed
{
case 'a':
::x--; //add 1 to global x.
break;
case 'd':
::x++; //minus 1 to global x.
break;
case 'w':
::y++;
break;
case 's':
::y--;
break;
case 'q':
::z--;
break;
case 'e':
::z++;
break;
}
glutPostRedisplay();
}

void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE GLUT_RGB GLUT_DEPTH);
glutInitWindowSize(640, 480);
glutCreateWindow("My Practical 6");
glutDisplayFunc(MyDisplay);
glutReshapeFunc(Rescale);
glutKeyboardFunc(Keyboard);
SetupRC();
glutMainLoop();
}

Thursday, November 22, 2007

PRACTICAL 5


#include "glut.h"

GLfloat angle= 0.0f;
GLfloat width= 40.0f;
GLfloat height= 30.0f;
int x=0;int y=0;

void MyDisplay()
{
glEnable(GL_DEPTH);
glClear(GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT); //glLoadIdentity();
glPopMatrix();
glBegin(GL_LINES);
glColor3f(1,1,1);
glVertex3f(0,0,0);
glVertex3f(400,0,0);
glVertex3f(0,0,0);
glVertex3f(0,400,0);
glVertex3f(0,0,0);
glVertex3f(0,0,400);
glEnd();

glPushMatrix();
glTranslatef(::x,y,0);

glColor3f(1,0,0);
glBegin(GL_QUADS);
glVertex3f(0,0,0);
glVertex3f(0,20,0);
glVertex3f(20,20,0);
glVertex3f(20,0,0);
glEnd();

glColor3f(0,0,1);
glBegin(GL_QUADS);
glVertex3f(0,0,0);
glVertex3f(0,0,20);
glVertex3f(0,20,20);
glVertex3f(0,20,0);
glEnd();

glColor3f(0,1,0);
glBegin(GL_QUADS);
glVertex3f(0,20,0);
glVertex3f(0,20,20);
glVertex3f(20,20,20);
glVertex3f(20,20,0);
glEnd();

glColor3f(1,1,0);
glBegin(GL_QUADS);
glVertex3f(0,0,0);
glVertex3f(0,0,20);
glVertex3f(20,0,20);
glVertex3f(20,0,0);
glEnd();

glColor3f(0,1,1);
glBegin(GL_QUADS);
glVertex3f(20,0,0);
glVertex3f(20,0,20);
glVertex3f(20,20,20);
glVertex3f(20,20,0);
glEnd();

glColor3f(1,0,0);
glBegin(GL_QUADS);
glVertex3f(0,0,20);
glVertex3f(0,20,20);
glVertex3f(20,20,20);
glVertex3f(20,0,20);
glEnd();

glutSwapBuffers();
} // Called by GLUT library when the window has changed size

void Rescale(GLsizei w, GLsizei h)
{
glViewport(0,0,w,h);
}

void SetupRC()
{
GLfloat final = width / height;
gluPerspective(90, final , 0, 1000);
gluLookAt(90,90,90,0,1,0,0,1,0);
glFlush();
glPushMatrix();
}

void Keyboard(unsigned char key, int x, int y)
{
switch(key) //check which key is pressed
{
case 'a': ::x++; //add 1 to global x.
break;
case 'd': ::x--; //minus 1 to global x.
break;
case 'w': ::y++;
break;
case 's': ::y--;
break;
}

glutPostRedisplay();
}

void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE GLUT_RGB GLUT_DEPTH);
glutInitWindowSize(640, 480);
glutCreateWindow("My Practical 5");
glutDisplayFunc(MyDisplay);
glutReshapeFunc(Rescale);
glutKeyboardFunc(Keyboard);
SetupRC();
glutMainLoop();
}

PRACTICAL 4


#include "glut.h"
void MyDisplay()
{
glClear(GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT);
glColor3ub(255,255,255);
glVertex3f(0.0f, 0.0f, 100.0);
glVertex3f(0.0f, 0.0f, -10.0);
glVertex3f(100.0f, 0.0f, 0.0);
glVertex3f(-10.0f, 0.0f, 0.0);
glVertex3f(0.0f, 100.0f, 0.0);
glVertex3f(0.0f, -10.0f, 0.0);
glEnd();

glColor3f(0, 1, 0);
glBegin(GL_QUADS);
glVertex3f(-35,-30,11);
glVertex3f(-35,30,11);
glVertex3f(-30,30,11);
glVertex3f(-30,-30,11);
glEnd( );

glColor3f(1, 0, 0);
glBegin(GL_QUADS);
glVertex3f(-40,-20,10);
glVertex3f(-40,-10,10);
glVertex3f(40,-10,14);
glVertex3f(40,-20,14);
glEnd( );

glColor3f(0, 0, 1);
glBegin(GL_QUADS);
glVertex3f(-40,20,12);
glVertex3f(-40,25,12);
glVertex3f(40,25,12);
glVertex3f(40,20,12);
glEnd( );

glColor3f(1, 1, 0);
glBegin(GL_QUADS);
glVertex3f(30,-30,13);
glVertex3f(30,30,13);
glVertex3f(35,30,13);
glVertex3f(35,-30,13);
glEnd( );

glutSwapBuffers();
} // Called by GLUT library when the window has changed sizevoid Rescale

(GLsizei w, GLsizei h)
{
glViewport(0,0,w,h);
}

void SetupRC()
{
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0,0,0,1);
glOrtho(-64,64,48,-48,1,50);
gluLookAt(0,0,20,0,2,0,0,2,0);
glEnable(GL_DEPTH_TEST);
}

void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE GLUT_RGB GLUT_DEPTH);
glutInitWindowSize(640, 480);
glutCreateWindow("My Practical 4");
glutDisplayFunc(MyDisplay);
glutReshapeFunc(Rescale);
SetupRC();
glutMainLoop();
}