Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/glut.h>
- void shapes (void) {
- /*glColor3f(1.0, 1.0, 1.0); //this will set a color of the square.
- glBegin(GL_LINES); // write shape u want to create
- glVertex3f(-0.5, -0.5, 0.0);
- glVertex3f(-0.5, 0.5, 0.0);
- glVertex3f(0.5, 0.5, 0.0);
- glVertex3f(0.5, -0.5, 0.0);*/
- /*glBegin(GL_POINTS);
- glVertex3f(.5,.5,0);
- glVertex3f(-.5,-.5,0);
- glVertex3f(0,.5,0);
- glVertex3f(.5,0,0);
- glVertex3f(0,0,0);*/
- /*glBegin(GL_LINE_STRIP);
- glVertex3f(0,0,0);
- glVertex3f(-.5,0,0);
- glVertex3f(.5,.5,0);
- glVertex3f(-.5,.5,0);
- glVertex3f(.5,0,0);*/
- /*glBegin(GL_POLYGON);
- glColor3f(1, 0, 0);
- glVertex3f(-0.6, -0.75, 0);
- glColor3f(0, 1, 0);
- glVertex3f(0.6, -0.75, 0);
- glColor3f(0, 0, 1);
- glVertex3f(0, 0.75, 0);*/
- /*glBegin(GL_TRIANGLES);
- glColor3f(0.5, 0.5, 0.5);
- glVertex3f(0, 0, 0);
- glVertex3f(1, .2, 1);
- glVertex3f(-.5, .5, 2);*/
- glBegin(GL_TRIANGLES);
- glColor3f(1.0, 0.0, 0.0);
- glVertex3f(0.0, 1.0, 0);
- glVertex3f(-0.5, 0.5, 0.0);
- glVertex3f(0.5, 0.5, 0.0);
- glEnd();
- glBegin(GL_QUADS);
- glColor3f(0.0, 1.0, 0.0);
- glVertex3f(-0.5, -0.5, 0.0);
- glVertex3f(-0.5, 0.5, 0.0);
- glVertex3f(0.5, 0.5, 0.0);
- glVertex3f(0.5, -0.5, 0.0);
- glEnd();
- glBegin(GL_QUADS);
- glColor3f(0.0, 0.0, 1.0);
- glVertex3f(-0.2, -0.5, 0.0);
- glVertex3f(-0.2, 0.2, 0.0);
- glVertex3f(0.2, 0.2, 0.0);
- glVertex3f(0.2, -0.5, 0.0);
- glEnd();
- /*glBegin(GL_QUADS);
- glColor3f(0.0, 0.1, 1.0);
- glVertex3f(-0.5, -0.5, 0.0);
- glVertex3f(-0.3, -0.3, 0.0);
- glVertex3f(-0.3, 0.3, 0.0);
- glVertex3f(-0.3, 0.1, 0.0);*/
- glEnd();
- /*glBegin(GL_TRIANGLE_FAN);
- glColor3f(1,0,0);
- glVertex2f(0,0.5);
- glVertex2f(-0.4,0);
- glVertex2f(0.4,0);
- glVertex2f(0,-0.5);
- */
- glEnd();
- }
- void display (void) {
- // clearing the window with black color, 1st 3 parameter are for R,G,B. last one for opacity
- glClearColor (0.0,0.0,0.0,1.0);
- glClear (GL_COLOR_BUFFER_BIT);
- glLoadIdentity();
- //viewing transformation
- //glulookat() positions the camera towards the object
- //camera position, camera target, upvector
- gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
- shapes();
- glFlush();
- }
- void reshape (int w, int h) {
- // 1st 2 parameters for lower left corner of the viewport rectangle. the default is 0,0
- // the next coordinates are width and hight of the viewport
- //Set the viewport to be the entire window
- glViewport (0, 0, (GLsizei)w, (GLsizei)h);
- // setting the camera
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity ();
- //perspective transform
- //gluPerspective (30, (GLfloat)w / (GLfloat)h, 1.0, 100.0);
- gluPerspective (30, 1, 1.0, 100.0);
- glMatrixMode (GL_MODELVIEW); //switch back the the model editing mode.
- }
- int main (int argc, char **argv) {
- glutInit (&argc, argv);
- glutInitDisplayMode (GLUT_SINGLE); // single buffering.. (double buffering for animation)
- // full screen is 1000,1000
- // this 0,0 or 1000,1000 are world co ordinates
- glutInitWindowSize (700, 700);
- glutInitWindowPosition (100, 100);
- glutCreateWindow ("A basic OpenGL Window");
- // registering callback functions
- glutDisplayFunc (display);
- glutReshapeFunc (reshape);
- glutMainLoop ();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement