Slides

sizzlepictureΛογισμικό & κατασκευή λογ/κού

2 Δεκ 2013 (πριν από 3 χρόνια και 10 μήνες)

96 εμφανίσεις

OpenGL Programming

Adam Hewgill

MSc Computer Science

ta480@cis.uoguelph.ca

http://teachweb.cis.uoguelph.ca/cs4800

Special Thanks to:

What is OpenGL?


Open Graphics Library


Computer Graphics API


Production Quality


Interfaces with Graphics Hardware


Multi
-
platform library


Originally created by SGI in the early 90’s


Controlled by the ARB since 1992


3D Labs, Apple, ATI, Dell, IBM, Intel, NVIDIA, SGI,
and Sun Microsystems


OpenGL In
-
depth


OpenGL 1.3


Released on August 14
th
, 2001


My first view of OpenGL as a programmer


Basic Shape Drawing


Lighting


Color Blending (Transparency)


Vertex Arrays and Display Lists


Texture Mapping (2D and 3D)


Texture LOD Mapping (Mip
-
mapping)


Anti
-
aliasing


Multi
-
texturing


DOT3 Environment Mapping (Early Bump Mapping)


Behind Direct3D 8 due to Pixel and Vertex Programs


Demise predicted by many on the Direct3D side


OpenGL 1.4


Released on July 24
th
, 2002


Vertex and Fragment (Pixel) Program Support


ARB Extension


Mipmap Auto Generation


Depth Texturing (Better Bump Mapping)


Fog


Various advances to other more specialized functions


Behind Direct3D 9 due to Pixel and Vertex Shaders


Most Graphics cards specialized for DirectX now


OpenGL 1.5


Released on July 29
th
, 2003


Vertex and Fragment (Pixel) Shader Support


ARB Extension


Buffer Objects


Occlusion Queries


Improved texture comparison for shadow mapping



OpenGL 2.0


Released on September 7th, 2004


Vertex and Fragment (Pixel) Shader Support


OpenGL Shading Language (GLslang)


Non
-
power of two textures


Point sprites (for particles)


Separate Stencil (shadow volumes)


Now includes full support of GPUs


However no GPU yet supports all of OpenGL 2.0


Now comparable to Direct3D


Still more stuff for Direct3D as seen on both the ATI and
NVIDIA SDK sites, most games still use DirectX


http://www.opengl.org/documentation/specs/version2.0/glspec20.pdf


What is GLUT?


OpenGL Utility Toolkit


GUI Windowing and Control API


Event
-
Driven System


Creates windows to display OpenGL view port


Handles Keyboard, Mouse, etc. events


May only be available for Windows and Linux
however source is on
-
line for porting


Windows http://www.xmission.com/~nate/glut.html


Linux http://www.opengl.org/resources/libraries/glut.html


Other alternatives


http://www.opengl.org/resources/libraries/windowtoolkits.html

How do we get started?


Linux


GLUT uses XWindows libraries


Check for /usr/include/gl/glut.h and gl.h


GCC is generally used to compile


OpenGL is either MESA (Software) or provided by
your graphics card (Hardware)


Implementations of open specs


Program using any editor you like


Include <gl
\
gl.h> and <gl
\
glut.h>


gcc filename.c
-
o outputname
-
I/usr/X11R6/include/

-
L/usr/X11R6/lib
-
lX11
-
lXi
-
lXmu
-
lglut
-
lGL
-
lGLU
-
lm


Windows


MinGW, MSYS


Visual Studio [ X | .NET | 200X ] Y Edition


Borland C/C++ Builder


DJGPP


etc.


Visual Studio 2005 Express Edition Beta


http://lab.msdn.microsoft.com/express/visualc/


Microsoft Platform SDK


http://www.microsoft.com/msdownload/platformsdk/sdkupdate/


Install Visual Studio then Platform SDK


Install Glut for Win32


Copy glut32.lib into lib directory


Copy glut.h into include directory


Copy glut32.dll into C:
\
Windows
\
system32


Open Visual Studio


Create New Project (Win32, Console Application)


Click Project in Solution Explorer (on right side)


Click Project
-
> Project Properties …


Select General under C/C++


Add C:
\
Program Files
\
Microsoft SDK
\
include


Select General under Linker


Add C:
\
Program Files
\
Microsoft SDK
\
lib


Add .cpp file to project


Include <windows.h> <gl/gl.h>


MAC


Sorry never done it before


http://developer.apple.com/graphicsimaging/opengl/index.html

Hello World

#include <gl/gl.h>

#include <gl/glut.h>


void draw ()

{


glClear(GL_COLOR_BUFFER_BIT);


glFlush();

}


int main (int argc, char **argv)

{


glutInit(&argc, argv);


glutInitDisplayMode(GLUT_RGBA | GLUT_
SINGLE
);


glutInitWindowSize(
100
,
100
);


glutCreateWindow(“Hello World”);



glutDisplayFunc(draw);



glutMainLoop();


return 0;

}

Hello World Analysis


Result 100x100 Blank Black Windows


glutInit(int *argcp, char **argv)



Sets up GLUT


glutInitDisplayMode(unsigned int mode)


Color Mode


GLUT_INDEX Indexed Color Mode :o(


GLUT_RGB Red, Green, Blue Mode :o)


GLUT_RGBA RGB + Alpha Mode :oD


Buffer Mode


GLUT_SINGLE Single Drawing Buffer


GLUT_DOUBLE Two Buffer Drawing


Extra Buffers


GLUT_DEPTH Allow space for Depth Buffer





glutInitWindowSize(int width, int height)


glutCreateWindow(char *title)



glutDisplayFunc(void (*func)(void))


Parameter is name of function for all *Func()’s


glutMainLoop()


Never Exits


Starts the Event Driven GLUT Engine


Round
-
Robin thru Callbacks registers


glClear(GLbitfield mask)


GL_COLOR_BUFFER_BIT Color Part of Buffer


GL_DEPTH_BUFFER_BIT Depth Part of Buffer


glFlush()


Forces processing of buffered commands


Just in case