Download presentation
Presentation is loading. Please wait.
1
Introduction : What is OpenGL
Software interface to graphics hardware Hardware-independent interface OpenGL's main purpose is to render two- and three-dimensional objects into a frame buffer.
2
Fundamentals Primitives and Commands
defined by a group of one or more vertices Commands are always processed in the order in which they are received Procedural versus Descriptive Execution Model client-servermodel for interpretation of OpenGL commands
3
Basic OpenGL Operation
High-level block diagram of how OpenGL processes data
4
Getting started with OpenGL
Initialisation Setting up the window for rendering Set up the correct window style and class attribute : WS_CLIPSIBLINGS and WS_CLIPCHILDREN Should have CS_OWNDC instead of CS_PARENTDC Set up a pixel format Create a device context Creating a rendering context.
5
Pixel Format Description of the actual format given to a particular window Some of the properties that you want some control over Single or double buffering Drawing to a window and/or bitmap Supporting GDI and/or OpenGL calls RGBA or color-indexed Color depth (bits/pixel) z-axis depth
6
Getting started with OpenGL Contd.
Tell OpenGL about the window you're rendering to and how you want your scene to be viewed Responding to the WM_SIZE message. Responding to the WM_PAINT message. Responding to the WM_ERASEBACKGROUND message. Responding to the WM_PALETTECHANGED, WM_QUERYNEWPALETTE, and WM_ACTIVATE messages (if you use a color-index pixel format). Deleting the RC and DC when your program finishes.
7
Initialisation
8
Simple example using OpenGL
Add OpenGL32.lib GLu32.lib and GLaux.lib Include the header files #include <windows.h> // Header File For Windows #include <gl\gl.h> // Header File For The OpenGL32 Library #include <gl\glu.h> // Header File For The GLu32 Library #include <gl\glaux.h> // Header File For The GLaux Library InitGL glShadeModel(GL_SMOOTH); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); ReSizeGLScene(GLsizei width, GLsizei height) glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f); glMatrixMode(GL_MODELVIEW);
9
Simple example using OpenGL : Contd.
DrawGLScene(GLvoid) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(-1.5f,0.0f,-6.0f); glBegin(GL_TRIANGLES); glVertex3f( 0.0f, 1.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f); glEnd(); CreateGLWindow() CreateWindow() Initialise Pixel Format PIXELFORMATDESCRIPTOR pfd ChoosePixelFormat(hDC,&pfd) SetPixelFormat(hDC,PixelFormat,&pfd) wglCreateContext(hDC) wglMakeCurrent(hDC,hRC) call ReSizeGLScene(width, height); call InitGL()
10
Frame Buffers Contain different amounts of data per pixel
Bitplane : A buffer that stores a single bit of information about pixels Color buffer holds the color information You can use GL_STEREO or GL_DOUBLEBUFFER Depth buffer stores a depth value for each pixel Stencil buffer to restrict drawing to certain portions of the screen Accumulation buffer holds RGBA color data accumulating a series of images into a final, composite image
11
Colors each pixel emits different amounts of red, green, and blue light can be stored either in RGBA mode or color index mode API used glColor3f (1.0, 0.0, 0.0);
12
Rotation Three major axes and therefore three rotations API used
glRotatef(Angle,Xvector,Yvector,Zvector)
13
Drawing Solid Objects glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Front) glVertex3f(-1.0f,-1.0f, 1.0f); // Left Of Triangle (Front) glVertex3f( 1.0f,-1.0f, 1.0f); // Right Of Triangle (Front) Display lists group of OpenGL commands that have been stored for later execution improve performance API's used gluint glGenLists() glNewList(listname, GL_COMPILE) glEndList()
14
Texture Mapping Textures are simply rectangular arrays of data
Allows you to glue an image to a polygon Texture mapping ensures that all the right things happen as the polygon is transformed and rendered Filtering Process of averaging or interpolating texels provide different trade-offs between speed and image quality API's used glTexParameteri() for GL_TEXTURE_MIN_FILTER and GL_TEXTURE_MAG_FILTER Parameter : GL_NEAREST or GL_LINEAR or MIPMAP
15
Blending Tells how to specify a blending function that combines color values from a source and a destination Occurs after your scene has been rasterized and converted to fragments, but just before the final pixels are drawn in the framebuffer Basic Alpha Blending result = ALPHA * srcPixel + ( 1 - ALPHA ) * destPixel API's glColor4f(1.0f,1.0f,1.0f,0.5f); glBlendFunc(GL_SRC_ALPHA,GL_ONE);
16
2D Texture Font use just one texture to display any of 256 different characters on the screen. average character is 16 pixels wide and roughly 16 pixels tall. Take your standard 256x256 texture it's easy to see that you can fit 16 letters across, and you can have a total of 16 rows up and down. glPushMatrix() glPopMatrix();
17
Quadratics used to create complex objects such as spheres, discs, cylinders and cones. GluNewQuadric() gluQuadricNormals(quadratic, GLU_SMOOTH); glTranslatef(0.0f,0.0f,-1.5f); // Center The Cylinder gluCylinder(quadratic,1.0f,1.0f,3.0f,32,32); // Draw Our Cylinder Tessellation to display of concave polygons, polygons containing hole, or polygons with intersecting edges
18
Masking two step process:
place a black and white image of the texture on top of the scene switch blending modes, and map the texture on top of the black cut out.
19
Clipping & Reflections
Requires stencil buffer Steps : gluSphere() glBindTexture(GL_TEXTURE_2D, texture[2]); glColor4f(1.0f, 1.0f, 1.0f, 0.4f); glEnable(GL_BLEND); // Enable Blending glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_TEXTURE_GEN_S); //enable Sphere Mapping glEnable(GL_TEXTURE_GEN_T); // Enable Sphere Mapping gluSphere(q, 0.35f, 32, 16); clearing the buffers define clipping plane eqaution : used for clipping the reflected image.
20
Clipping & Reflections : Contd
set the color mask to white glColorMask(0,0,0,0); enable stencil testing glEnable(GL_STENCIL_TEST); glStencilFunc(GL_ALWAYS, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); Draw the floor Change the color mask to opaque enable the clipping plane draw the reflected image
21
Shadows Extensively uses the stensil buffer
A shaded region is a region in a scene that cannot be "seen" by a light source. INFINITY : how far to extend the shadow volume polygons Data reuired for casting a shadow : array of vertices vertex normals : to calculate orientation of the face plane equation indices into the array of faces in the object : to define edges
22
Limitations Printing OpenGL and GDI graphics cannot be mixed in a double-buffered window There are no per-window hardware color palettes. There is no direct support for the Clipboard, dynamic data exchange (DDE), or OLE There is no support for the following pixel format features: stereoscopic images, alpha bitplanes, and auxiliary buffers
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.