Computer graphics
This presentation is the property of its rightful owner.
Sponsored Links
1 / 22

Computer Graphics PowerPoint PPT Presentation


  • 66 Views
  • Uploaded on
  • Presentation posted in: General

Computer Graphics. CS 385 February 7, 2005. Fundamentals of OpenGl and Glut. Today we will go through the basics of a minimal OpenGl Glut project, explaining the role of each piece of the code. #include <GL/glut.h>. Includes gl.h and glu.h. Contains all the Glut constant definitions

Download Presentation

Computer Graphics

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Computer graphics

Computer Graphics

CS 385

February 7, 2005


Fundamentals of opengl and glut

Fundamentals of OpenGl and Glut

Today we will go through the basics of a minimal OpenGl Glut project, explaining the role of each piece of the code.


Include gl glut h

#include <GL/glut.h>

  • Includes gl.h and glu.h.

  • Contains all the Glut constant definitions

  • Contains all the Glut function declarations

  • Put glut.h in the GL sub-directory of your compilers include directory


Computer graphics

main

The main function takes two (optional) parameters

  • int argc

  • char* argv[] or char** argv

    argc is the number of parameters passed to the main function

    argv[] is an array of strings containing those parameters


Glutinit

glutInit

glutInit initializes the GLUT library. It takes two parameters from the main function.

The declaration of glutInit is

void glutInit(int *argcp, char **argv);

In addition to initializing the GLUT library, glutInit will negociate a session with the window system.


Glutcreatewindow

glutCreateWindow

  • Creates a top-level window

  • Declaration:

    int glutCreateWindow(char *name);

  • name is registered with the windowing system and also is used as a lable for the window.

  • The integer returned is an id to identify the window in a multi-window situation.


Glutdisplayfunc

glutDisplayFunc

  • glutDisplayFunc sets the display callback for the current window.

  • Declaration

    void glutDisplayFunc(void (*func)(void));

  • This might look odd to you.

  • Let’s review function pointers.


Function pointers

Function Pointers

  • In C++ you cannot pass a function in as a parameter to another function.

  • Instead, C++ allows you to pass in a pointer to the function.

  • Lets review function pointers. Here is and example:


Computer graphics

#include <iostream>

using namespace std;

void call(int (*func)(int i), int i)

{

cout << func(i) << endl;

}

int square(int i)

{

return i*i;

}

int main()

{

call(square, 3);

return 0;

}


Computer graphics

init()

The init() function is not a GLUT or GL function. It is our own customed made function which contains the code to set up the OpenGL environment.

Typically, in this function we pu these lines like these

  • glClearColor(1.0,1.0,1.0,1.0);

  • glColor3f(1.0,0.0,0.0);


Glutmainloop

glutMainLoop()

  • Declaration

    void glutMainLoop(void);

  • glutMainLoop enters the GLUT event processing loop.

  • This routine should be called at most once in a GLUT program. Once called, this routine will never return. It will call as necessary any callbacks that have been registered


Glpointsize

glPointSize

  • Declaration

    void glPointSize( GLfloat size )

  • specify the diameter of rasterized points in pixels


Lines

Lines

  • A Simple line

    glBegin(GL_LINES);

    glVertex2f(-1.0,0.0);

    glVertex2f(-1.-1.0);

    glEnd();


Line width

Line Width

  • Declaration

    void glLineWidth( GLfloat width )

  • Specifies the width of rasterized lines.

  • The width is in pixels

  • The default is one.


Lines1

Lines

  • GL_LINES works with pairs of consecutive points. If you give it three points, it will ignore the third.

  • To connect three, use GL_LINE_STRIPS

  • This has other properties too.


Line strips

Line Strips

glBegin(GL_LINE_STRIP);

glVertex2f(-1.0,0.0);

glVertex2f(0.0,-1.0);

glVertex2f(1.0,0);

glEnd();


Line strips1

Line Strips

  • In general, GL_LINE_STRIP will start at the first point, draw a lines segment to the next point, then to the next all the way to the last point. It will NOT however, connect the last point back to the first point.

  • For this you need GL_LINE_LOOP


Line loops

Line Loops

glBegin(GL_LINE_LOOP);

glVertex2f(-.5.0,0.0);

glVertex2f(0.0,-.5.0);

glVertex2f(.5.0,0.0);

glEnd();


Experiment

Experiment

glBegin( PARAMETER GOES HERE );

glVertex2f(-.5.0,0.0);

glVertex2f(0.0,-.5.0);

glVertex2f(.5.0,0.0);

glEnd();

Try the above code with GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_LINE_LOOP AND GL_POLYGON


Quads

QUADS

GL_QUADS takes points four at a time and makes quadrilaterals out of them.


Triangles

TRIANGLES

GL_TRIANGLES takes points three at a time and makes triangles out of them out of them.


Other types

Other Types

Look in the book at

  • GL_TRIANGLE_STRIP

  • GL_QUAD_STRIP

  • GL_TRIANGLE_FAN


  • Login