DOC PREVIEW
CSUN COMP 465 - OpenGL Application’s Architecture

This preview shows page 1-2-3-20-21-40-41-42 out of 42 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

OpenGL Application’s architectureintro open gl 1Glew extension library loader (3rd party)Freeglut GLUT Utility Toolkit, system independent (3rd party)GL OpenGL primitivesglm OpenGL Mathematics includes GLSL-like math on-line glut manual // many glut features are "compatibility mode"http://www.opengl.org/resources/libraries/glut/spec3/spec3.htmlapplicationincludes glmFreeglutGLsystem and other librariesGlewAPI Descriptionintro open gl 2State MachineFunctions set current state variables: polygon mode, cullingglEnable(GL_CULL_FACE)glCullFace(GL_BACK) Function naming convention:<library> gl // core<method name> [ <number of arguments> ]*[ <type of arguments> ]*{s,i,f,d,v}glBindBuffer( GL_ARRAY_BUFFER, buffer );glUniformMatrix4fv( MVP, 1, GL_FALSE,glm::value_ptr(modelViewProjectionMatrix) );Programming Languagesintro open gl 3Device LanguageDescriptionComputerC++Application specific OOP codeclasses for visual objectsCglut functioncallsOpenGL function callsGPU glslvertex, shader manipulationEverything is not an object C++ is a hybrid OOP (procedural and OO). It can have methods (like main) outside of any class definition.Application specific classes have methods that will make OpenGL calls.class Object3D's draw function could call glDrawArrays(...)Do not attempt to write OpenGL / glut function handlers in classes.OpenGL app's structureintro open gl 4usersystem (timer), keyboard, mouse eventsapplication program// C++ C code: glut, glm, OpenGL functionsglut*window (...) // interface to host OSglutDisplayFunc ( display ) // draw fn()glutReshapeFunc ( resize ) // resize fn()glut*func(....)  app fn(...) // handle eventsglewInit() // enable extension handlerinit(...) // create and load models  buffers// load, compile, ... glsl programs// create, update, M, V, P matricesglutMainLoop() // respond to events, rendershader programglutPostRedisplay()  glutSwapBuffer() vertex.glsl  fragment.glsldisplayrefresh GPU frame buffer# define and # includeintro open gl 5File: includes465/include465.hpp// defines and includes// OpenGL PG 8th ed. code, in vgl.h # define BUFFER_OFFSET(x) ((const GLvoid *) (x)) # define MAX_INFO_LOG_SIZE 2048 // for error messages# include <stdio.h> // My examples use printf# include <stdlib.h># include <sys/stat.h># ifdef __Linux__# include <GL/glew.h># include <GL/freeglut.h>// include the glm shader-like math library# define GLM_FORCE_RADIANS // use radians not angles# define GLM_MESSAGES // compiler messages# include <glm/glm.hpp># include <glm/gtc/constants.hpp># include <glm/gtc/matrix_transform.hpp># include <glm/gtc/type_ptr.hpp># include "../includes465/shader465.hpp" // load shaders# include "../includes465/triModel465.hpp" // load AC3D tri model # endifintro open gl 6# ifdef __Windows__# include <Windows.h> # include <GL/glew.h># include <GL/freeglut.h>// include the glm shader-like math library# define GLM_FORCE_RADIANS // use radians not angles# define GLM_MESSAGES // compiler messages# include <glm/glm.hpp># include <glm/gtc/constants.hpp># include <glm/gtc/matrix_transform.hpp># include <glm/gtc/type_ptr.hpp># include "../includes465/shader465.hpp" // load shaders# include "../includes465/triModel465.hpp" // load AC3D tri model # endifintro open gl 7# ifdef __Xcode__ # include <GLUT/glut.h>// include the glm shader-like math library# define GLM_FORCE_RADIANS // use radians not angles# define GLM_MESSAGES // compiler messages# include <glm/glm.hpp># include <glm/gtc/constants.hpp># include <glm/gtc/matrix_transform.hpp># include <glm/gtc/type_ptr.hpp># include "../includes465/shader465.hpp" // load shaders# include "../includes465/triModel465.hpp" // load AC3D tri model # endifconst float PI = 3.14159f;Programmable Pipelineintro open gl 8client (application)  display serverThe application runs in the computer’s space and makes drawing requests to the display server (GPU)Simplified programmable shader pipelinesprogramvertex shaderfragment shaderprimitive assemblyframebufferscale, translate, rotate verticescovert to view coordinatesclip to viewing volumeDetermine lights' contribution to each pixelset pixel'scolor or textureintro open gl 9Callbacks are a indirect function calls  event driven “on demand” appsConnect user code with pre-built library routines.• library has a callback resource (entry in array...) for user behavior• user writes function, “registers / adds” function to callback resource• executing program can call user function from library functioncompiled library code...typedef struct {void (* fn)(...); ...; } Callback;Callback cb[n];...void addCallback( void (* fn) (...), int cbId){...} ...void leftButtonPress {} {cb[LBN]-> fn(...); }...user’s code...void myPress(...) {...}...int main () { addCallback(myPress, LBN);...}left button presslibrary user’s function GLUT Callbackssystemapplicationintro open gl 10GLUT Vs. openGL coordinate systemsFreeglut uses a window manager's coordinate system.openGL uses a right handed coordinate system.Freeglut mouse drag (x,y) values are in the Freeglut coordinate system....X Y YXZhttp://www.opengl.org/documentation/specs/glut/spec3/spec3.htmlViewportglViewport(x, y, width, height); // origin, offsetsInitially the size of the window created. Place in resize function to adjust accordingly.intro open gl 11GLUT windowsint glutCreateWindow(char *name); The initial window is at -1, -1 with a size of 300 by 300.void glutInitWindowSize(int width, int height); void glutInitWindowPosition(int x, int y); void glutSetWindowTitle(char *name); void glutSetIconTitle(char *name); void glutFullScreen(void); void glutSetCursor(int cursor);intro open gl 12glutPostRedisplay() explicitly calls the rendering function set with glutDisplayFunc(...).glutSwapBuffers() causes double buffered output to be displayed -- usually last stmt in rendering function.the rendering function is also called on window changes after the call to the resize function set with glutReshapeFunc(...)the render function has (int width, int height) args.glutTimerFunc(...) sets the timer function to be called after an interval (msec) occurs. A user specified int value can be passed to the timer function. (animation)glutIdleFunc(...) sets the idle function to be called when there are no other events pending. (background sensor reading...)GLUT displayintro open gl 13GLUT keyboardX and Y arguments are mouse position in window coordinates// set handler glutKeyboardFunc(void (*func)(unsigned


View Full Document

CSUN COMP 465 - OpenGL Application’s Architecture

Documents in this Course
Load more
Download OpenGL Application’s Architecture
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view OpenGL Application’s Architecture and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view OpenGL Application’s Architecture 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?