WWDC2000 Session 186
Transcript
Kind: captions Language: en to that and talking about how you can get started in OpenGL and exactly what Apple's OpenGL implementation how it's made up first of all this is going a high-level overview of OpenGL we're going to talk about a little bit of lamp applicable entation and the set up for an introduced OpenGL and talk about how that works and then we're example implementation and give a little bit of how to to get you're going to lead into the next session first we'll talk about what is OpenGL exactly how does it fit in what does it do and for some people kind of heard OpenGL term bounced around a lot which we talked about it we said this is a great thing but how is it a great thing for you what can you do with it and we'll talk about our implementation details we'll talk about using OpenGL and we'll give you some references to get started and to get you on your way they'll give you some really good source coding some the documentation for it first OpenGL really is just a software interface for graphics hardware it drills down and allows you to really get at the meat of the hardware and with all the research we're doing these days in the 3d hardware the companies are doing it really allows you a really good way of getting high performance graphics to the screen its platform agnostic so a lot of you who have things that may run on unix or may run on windows or may run on the mac OS OS 9 or OS 10 can use the same open GL graphics code for both and have that stay the same across multiple multiple platform for your application so it solves your development problems that way it doesn't mean don't write windowing code for every single application and write the specific graphics engine for every different platform you're on it's also a synchronous this is a key to understanding OpenGL we have a graphics engine and you have your application you're submitting commands for the graph extension this kind of comes back from when it was originally from from the FBI design that you could have the graphics you have a client-server kind of operation that you would not have in what you'd say a pc today we've carried that over and everyone to carry that over when they build OpenGL and what that does is mean that your commands are submitted and then you swap the buffers and it basically execute batch of command and displays you whatever your your image becomes on the screen it's also based on geometric primitives instead of some higher-level languages that might be PDF based like quartz or they might have a file handling capability doesn't have that what it has basically it has the basic points lines and polygons and you build them from the bottom kind of up and real important to understanding OpenGL is it it's a state machine when what state you said it in is always a state it's going to be in if you turn texturing on it's going to stay on until you turn it off if text rings off initially if you try and text your polygon you're not gonna get any texture you're probably anyone will get a white polygon cuz it's not going to apply a texture until you turn the texturing on and there's lots of examples of that and a lot of new OpenGL program which myself included have been bitten by that many times that's about it let's move on so we talked about it just as a state machine as I said this is a key to understanding OpenGL and successful development with OpenGL by understanding it's a state machine you under you can understand why things happen in your application and as I said with texturing you can add almost anything in an OpenGL including the Mo's not just the switch kind of mode but including some of the drawing modes are again states and you can change drastically the behaviors application by setting simple states also state changes can be expensive sometimes they're not but a lot of cases they can be if for example you design an engine to draw something on the screen that every frame goes through and sets every single state that you need set in some cases you can really be seeing some long paths through our drivers and through OpenGL but making your application run significantly slower than it could run if you actually expect the state once and then think about when you need to change it so for example if there's only two things in your scene one it's extra math and what it's not texture map drawl everything is texture maps and then Darrell everything it's not texting maps that switch once rather than on a per polygon or a poor coin basis so also we talked about setting in getting states it's really key when you want to know what its stay on a set of state or how to get it stays you can use GL enable and disable therefore throughout the API you can use them for almost every state documentation covers the litany of states that you can set also there is a geo is enabled and a GL get key here also sometimes that has to query the hardware and to do that it since it is an asynchronous operation you can have a command that changes of state somewhere in your pipeline if you call a GL get they hate is texturing enabled what happens is in it may have to wait for the whole command pipeline to execute the query the hardware to say mi in that state get the command back so as you can see that could be an awesome an expensive thing so that's not a shortcut it's not just not a state that is always saved off in the software it really ties the software opengl drivers and the hardware are tied together very closely and GL push on tribute and pop attribute the reason i mention these is sometimes if you want to change a lot of states you have a pile of things are changing you may want to use push on screen and pop out treats a lot of times as we faster to do that than it is to save all your states or check your state's enable your state's disable your state's one at that time so let's talk a little bit about the OpenGL pipeline real simply the OpenGL plug is a really high level overview of the pipeline I say that you might want to go to the references and there's a lot of in the specification and all the references a lot of more in-depth in-depth section on the OpenGL pipeline so I'm not going to really go deep into this but it gives you an idea of how it works and so this is all your data comes into this pipeline and first thing that vertex is come into so if you have a vertex you have a point in space it comes in there and basically when the vertex comes in it applies transformation that puts that vertex somewhere in space it says okay the model transformation it's over here by the podium and then it takes transformations of view transformation based because I'm looking at it from this perspective and so that sets off the relationship between the point and the eye and also the projection transformation which actually projects that point from your 3d space into your 2d flat screen that all happens in the vertex operation then we clip the thing prospective provides v4 train information happen so we actually transform it into what size of you pour it is you'll see one of the applications I'll demo later that you can drag the window and make it larger that's of you translate that and just resetting the viewport to a size prospective divided basically scales things via your Z or how far away it is making smaller far away and closer and closer it can make and when things are closer makes them larger obviously one key here is the perspective divide is based on information you supply to opengl it's not based on opengl always does this it's a 3d application it has to look exactly this way for example one thing we'll talk about later in the week is using opengl for like not a game or not a immersive 3d application you can say hey I want this to be orthographic I don't want that perspective I want everything to be directly parallel projection and I'm going to make everything the same size no matter how far away it is and you can do that if you're marrying a cad program for example so these are things that it does in general but depending on how its set up in what state status in maybe depending on how actually it carries out these and it calls either it can do back face culling so if you have my proverbial cube and i don't want to show the back faces of that cube because maybe it's transparent it will look at the polygons and determined based on whether it's clockwise or counterclockwise would polygons to throw away that may be facing away from you now we talk about pixel operations pixel operations are parallel to the vertex operations if you put a texture in there or you put a bitmap into opengl they go to the pixel part of the pipeline and they basically pixel to unpack and sorted into a format that opengl sand understand that's real important because when we talk about texturing later opengl expects with certain types of formats and you need to be all supplied this pipe before my graphics for it to expect and you'll see what we have some good news in that area as i get through the presentation here pixel master process and their past is past in your texture memory or to the raster rights to be drawn so basically it hands it off the texture memory here you go here's your form your bits bits in pixels in form in the proper format and then when it's when the texturing instructions come in they can pull that texture out and ink texture to the screen rasterization rasterization basically takes your geometry and pixels and conversing the fragments fragments is something that represents basically one pixel on the screen as you notice at the bottom of this slide I have XYZ wrgb st r and q so those are basically that's a point of space so it has an x y and z value you may say hey didn't you just say that was already you know we're already converted to 2d we didn't we do this perspective divide thing why do I have a Z well you can do def sorting with this fragment so when if you have depth when it turns on turns into a fragment says hey am I in front of everything else I'm Iceni full eat opaque and I'm in front of everything else this is a fragment should actually be this fragment instead of the fragment behind it RGB is obvious str and q are using texture mapping but basically so this converts everything to the single pixel on the screen and allows it to then be drawn to the screen and lastly we do fragment operations which is texturing and fog so it says hey I got this colored pixel is it may be white maybe grain to be blue but now I want to find what piece of a texture Maps corresponds to that will single pixel and I color that pixel width of my piece of text match if we're doing text string it fogs applied if clockwise the appropriate fog and it can do scissor checkings is coming down alfo stencil buffer or depth tests are all done in here so this is going talk about deaf textme of multiple fragments with different depth it's going to take the front one but one couldn't have analysis value so you may have you may have some different interactions there but this is where it's done okay what does open to y'all not have this is what people don't understand a lot opengl it doesn't have a built-in windowing system it doesn't know about math windows doesn't know about Windows Windows it doesn't know about unis windows it doesn't know how to draw things to the screen so on the math we have a GL we have n SGL we have glutton we have NS open opengl view these are all ways to set up in an environment that opengl can use and use that to draw into a GL is fairly simple to work with because it can be used for with OS 9 + OS 10 n stl can be on 10 glutes on OS 9 and os 10 and NS OpenGL view is also on OS 10 there are different ways to work with it the NFC l and the NSO pgl view are both object oriented is OpenGL view is kind of interesting because you basically can do everything you instantiate an end to OpenGL view object in it already sets up your OpenGL for you you're ready to go it also doesn't have input methods input methods are oh s specific thing so for example if you after a mac OS a pair of a normal keystroke so those kind of things it open shelves just a graphics API it does not have any kind of input if using glut off obviously also without plus a little bit about later glut has its own keyboard in your face and mouth interface it also does not have file handling there's one of things that opens y'all being a lower level API rather than a high level API it doesn't have the handling of an importer for certain kind of file if you build a model in my on you export it doesn't have intrinsically a way to read that Maya model in and would display that you have to work you have to put that together or do some stamps code is already created it also does not have like I said that high level modeling doesn't many tools built in to do high-level modeling or understand high level models high level models have a certain way of texture mapping it also can have a certain way of handling a hierarchical structure like a like a skeleton and that's not built in you can decide how to do that and that's something for you to do in your application or you don't have to if you don't have high level models you want to display some small things or some primitive zor do you use them the primitive drawing you don't have to build a complete handling system for every file out there okay now we're gonna talk about APIs implementation first thing I'll do is go quick overview of what hardware we have out there now I probably up some new Mac developers out here but we have some old faithful few real review for you guys then I'll talk about some frame or coerce 9 + OS 10 I'll talk about what extensions were supporting I'll talk a little bit about glut and I'll talk about a GL and setup GL so current Hardware it's obviously the ibook the imac the powerbook and power the ibook is the first part of standard but the key here if you're working with opengl is what kind of graphics hard roads are going to support as a rage mobility graphic cross which is basically like a rage pro it has 4 mega vrm and a gp2x so what does that tell you the for Meg of vram says about how much limitation you have on texturing and buffering when you're working with opengl it's not critical to understand but something you do want to understand is the fact that if you're doing opengl you have a front window you have a screen that takes up a certain amount of vram you have a back buffer for your opengl window that takes a free ram and you also have a depth buffer which may take up the ramp and any textures you upload also going to be in the vram so thinking about what the configurations are shipping to what kind of vram is kind of critical and also that i would say testing on multiple systems is also critical for opengl i'll tell you a little story hero i came in to do my demo I brought my powerbook game works great I demos run great they're really simple shouldn't be any big deal posted up here turned on video mirroring forgot that the vram was split between the mirrored and my powerbook display and when I am when I loaded my texture it was doing texture paging so that's something that's a good reason to go chest your app on your mobile platform to make sure you're running and makes you understand the constraints of running your app I'm asked as a rage 128 VR graphics boss is a really great thing to work with I mean if you have a imac you can surely do open to opengl development it has really good support for OpenGL and is one of our you know the rate which ways art or top process that we're going to support as far as feature set so you're going to get all the features there 8 mega vram that's good gp2x also powerbook 400 500 megahertz powerbooks ati rage mobility 128 graphic controller 8 mega vram and 82 x one thing that i have to say is that this is one of the kind of unsung heroes of mine of our product line for me because I'm like this is great you can get this even to opengl working i mean i used to develop opengl and i run on a rage 2 which is you like 200 x 100 window and looking at do this bit right so this is great to have this you can develop full speed applications you can build about full screen applications you can work on your powerbook wherever you are without having to sacrifice the graphics processing the power mask the rage 128 pro graphics processor up to 16 mega VMM in ATP 2x they're also third-party hardware and supported formats 3dfx both have good offerings 3d effects is obviously an ounce full map supporting they're going to be rolling out some really high powered cars and so you know we're looking also so you can add for people to add on cards you get more performance even than we may supply initially okay let's talk about how opengl structured in the OS so for mac OS 9 implementation framework we have an application we have a little setup code the reason I segment those out it's because as I said OpenGL does not have a windowing system it does not know all about how to draw to a window does not know what your windows are like so the setup code is what handles a slice a setup I say constructing your window and telling OpenGL where this is where it's going to draw two ways to do setups in mac OS 9 through the glutes which I'll glut handles a setup for you basically you say hey this is my window here so here's what I want and it builds it for you or a GL which you build your window and you say I want a certain pixel format here's my drawable that window and I'm passed to you and you're going to take care of that you're going to use that for me once you get past that you can see that then you're actually can talk to OpenGL directly an application for glut application can actually do some things in glut to produce output but also it can go directly to OpenGL once you have the setup done and so we didn't you go through OpenGL make all the GL calls once you have the setup done and then that goes passes through to the drivers which handle actually drew rasterizing and drawing things to the screen oh it sends a little more complicated OS 10 there's a lot of different ways to set up but if you notice that the application still is using glut or is using opengl that hasn't changed you can pick a lot of different options for setting up but in reality you're opengl your application code doesn't change i have a number of example of been working on over the past few weeks for some of the demos and just for some live stuff on OS 10 and I didn't change any money with my OpenGL code none zero I mean all I did was change my setup code which is really a good story because it means you can move your applications that may be online forward and you can create applications of run on 10 run on nine run on Windows run on unix without having to change your code every for everything a block on specific you've got to change the most setup stuff we talked about some of these vienes OpenGL view is available in cocoa we also have got which is gonna be available and the glut this is available will be available on OS 10 and OS 9 and there are different implementations but they should be a code compatible glut if you don't know is a basically a free not really distributable as far as better ways say that it is not given to you free we it's not our application mark chill Guardsmen who used to work at SGI wrote it and he distributes it freely but it's not he still owns the source code you're not free to go and change it and call it yours and resell it or something like that NSEL is also their blood isn't playing on top of it and NFC all open view calls into NSEL ADL's their work works basically the same on 10 and 9 they call into the low-level core graphics GL so cgl and that goes to the colonel into the drivers so the key here is to understand is there's lots more ways to get out open gel key of a cocoa application no problem set up OpenGL through cocoa through nsdl off you go Dave spring or summer toss in the next tacos will show you some demonstrations are using NS GL and show you how easy that can be ok this is what we have for extensions right now a couple apple extensions it may improve some rendering from transformed hint compiled vertex array for speed quake uses that multi-textured places ask you a lot of people use multi texture texture texture working and sexy and V add well I can tell you right now is that we've had a lot of developers and say I need this I need pack pixels I need to sell their format and then actually let me back up a little bit extensions OpenGL those videos you're not familiar if I may have moved a little bit too fast here with opengl opengl has a has a particular graphics API to find it has a message by providing extensions that extend that api for example with with the multi texture it allows you to do multi texturing layering more than one texture on top of each other in OpenGL and passing that to the OpenGL pipeline rather than having to do in software where you might blend things together and then pass it as a single texture so there's I mean there's a litany of extension there's a lot of extensions out there we pick some of those some of those to implement some of them are vendor specific vendor specific so they might be an SGI only thing or and some of more XP type which are multi-vendor obviously we have to vendor specific ones here and the rest of multi-vendor there's a lot of other extensions that people say can handle textures is better can do some some more confined of combining textures and we haven't self to this point having supporters that what i can say is that basically as of i'll tell you the availability money gets i'll tell you the building right now OS 9 the ADC seating in the in very shortly we're going to have these extensions available on a feed for opengl 12 which will be a 1 122 compliant opengl one of the keys here is our software implementation and our the API you can write to is 12 to compliance with opengl there's two pieces is a driver piece and there's the our implementation piece as drivers come up to speed with 122 you get a full OpenGL 122 implementation but the key here is you can get these extensions very shortly proceeding and then after that they'll be in our next OS rev1 when we bring that out next OpenGL rep also for OS 10 the same set of taxes will be available the same time extension will be available for OS 10 very shortly so for developers who want to look for use these things that they'll be available very shortly and pay attention to the OpenGL list and also in the ADC seating and they should be available for download for installation on to DP for onto Mac OS 9 we're looking for Apple pack pixels and some people who are familiar with tackling why is it Apple pack pixels we're extending a little bit to recognize the kind of pixel formats we need but it should be the same as normal pack pixels of a transpose matrix we Nate ABG are so we can do different pixel ordering pixel color ordering and a whole bunch of others we may even add to this if we see that there are some that the developers are looking for so you know this is this design good news for developers we can really get extend your ability to develop on the platform ok let's talk about glut a little bit got is GL utility tool kit as I said it was written by Mark kill guard of SGI written written in a number of years ago it's available as source code through a number of different vendors we give it out with our SDK is also as source code and when we first brought the OpenGL speak a 10 out we brought gloat over to the math which is on Windows and union actually ported that in this 36 format which has some things that lacked reported that to the mac with the 10 SDK shortly we'll be releasing this a 37 version of glatt but includes a couple new things included game game mode or game glut which basically allows you to full screen mode on on glut and also some contextual menu support which is a normal way for a lot to operate we're finishing this up right now and this should be sealed off and should be out with our next SDK released shortly some bug fixes we're going on nine or better child window handling and just from general bug fixes 37 it should will be available for Mac OS 9 Mac OS 10 and i asked i have to actually think that is this correct but the 37 api maybe- game mode should be on the DP for CD and that's correct so through so glad 37 is on DP for and all the exams a significant amount of examples that we have gone with it will be there also so what is why do we do use glutton I would not I would honestly say glad is probably not something you would want to use for a shipping application if you want to build a little over to OpenGL experiment with it if you want to check out all kind of a rendering technique or do something do some work on an engine that you may want to put into glatt that might be a good framework just to work with it it provides an API or a platform agnostic a GUI environment I'll saying GUI that a little bit of a GUI environment basically gives us a platform set out of the setup for the window handle some input handles keyboard handles and mouse events handles menus and those kind of things and your code can open window to math to you next without really any changes the AGM set up GL I alluded to this a little bit earlier we talked about on a GL and setup GL Oh GL is Apple GL it's basically our interface to get to the GL this is the thing that handles Windows setup it handles handles base with all the pixel format that handles some utility and some error codes AGL is available in mac OS x it's also available on mac OS 10 for carbon and you can write basically the same code in kit mac OS 9 in mac OS 10 and i've been working on some is working some stuff that basically compiled one binary runs on 9 runs on ten runs on OS 9 as an OS non-carbon and the stems are 11 set of code and the same code runs on ten wasn't that difficult to do they're talking about you know a few weeks to carbonize it it took me two or three days to do it may be him probably an afternoon probably really for four or five hours at one sitting spread across three days and what instead of GL if you're not familiar with OpenGL on the math and you're not pay attention to our needs to our OS OpenGL newsgroup you probably haven't heard of it it's actually a piece of sample code that you can have all the source to what I try to do is in our sample code we have a section we call more is better and there's more network setup there's a more files that some of our other engineers have written and what they've done is basically trying to accomplish a real significant piece of the functionality that you will need into a piece of sample code instead of having a sample code that shows okay here's how to draw a square in OpenGL instead of just doing the absolute minimum trying to do better error checking better better error returns tried to add in actually handling uh you know your vram requirements so you can send a different food memory requirements handle fullscreen fullscreen window switching so one call heat you a full screen contacts you can call us you can destroy that context and call one call again and get you a window to the same thing so it's not limited to just doing one thing so it's it I think it's a reasonable thing to start with it gives you a good either a good base of source code or you can use it directly setup GL is not go away sign currently I'd say carbon swimming that's actually not correct as of when this presentation was written it was carbon soon now it is carbonized and it should be out this week on on the a on the MCM farts no se a DCC to be on the sample code site you should have a carbon version of it you can run in carbon and run on mac OS 10 DB four and in and in OS 9 so HDL we're going to talk a little bit more about AGL a little bit more about the specifics of a GL Oh GL handles we're talk about the basics then it handles pixel formats handles contact Straubel swapping ponts and errors so what are all other things first the basics as we talked about before handle set up and it'll SWAT and set up a nail swap and improvised utility function if you're familiar with windows at all you'll see the enet GL drawable which is defined as a GL and that's the main construct that you're going to pass the GL and say this is what you're going to draw on its equivalents basically 2 a.c window pointer which is also equivalent on Windows to an HTC so that's kind of the equivalent see if they're coming from wgl the key here is that people sometimes try and get away away from miss it well I can need to see graph pointer I can just point to my money on my off screen or i can point this piece of memory i can point to whatever i can grab and grab a seat pointer on the screen and just draw to that a key a real key for GL here as it uses the information in the window pointer to figure out what piece of hardware you're rendering on if you have two cars when 3dfx one's apple and you drag your window from one monitor to the other using a gel correctly if you have a window pointer you can fairly easily do that and it'll render on one render on the other no problem if you pass it a see graph pointer probably best cases you start on your main monitor to render correctly you can move it off and they not render anything if you start on you have your window on your secondary monitor you pass the seagrass pointer it'll probably draw on the upper right corner of your main monitor just over everything else so the key here is used a window the window information important you can't substitute a seagrass pointer in this case in HCL context and a gel context basically maintains an AGL state and a GL stay with that I so basically you can switch between contacts now switch between one rendering state to another rendering state that's the same as h GL RC i love this one man says it's great we have a nice AGL context and they have capital h GL RC so what is in atl physical format we say isn't that like what's on the screen well not quite an age L pixel format may be a misnomer a gel pixel format actually is a request for a drawing mode it has some more things in it you can tell it you know rgba you can say you want to double buffered you can say you want to back buffer or against our depth buffer you can say how deep the depth buffer is a lot of responsive occation to the Ajo pixel and it's not just saying I want 20 you know pretty two-bit 16-bit eight bits whatever it's more than that we'll go through that in a minute but its equivalent to the pixel format descriptor I like that so moving on pixel format ok so two bit main things we're going to use is a GL choose pixel format in a jail destroyed pistol format and please if you're doing GL check for errors check for a GL errors it's reasonable that one that if you give it a pixel format that's not supported on a card or in software or on this other monitor you're using or whatever it may sail and if you go off and marry your merry way and instead of your context and draw your GL you're wondering why you're not getting anything or why your programs crashing it's because you could have not returned to valid pixel format says hey I can't do this so you have a said it has to be span what is actually just a shlee say well in this case is telling a GL you want a red green blue and alpha buffer you want it to be accelerated you want to be double buffered and then the AGL nun says you terminate that that set of attributes you'll do this this for every kind of pixel format you work with you can add a double back buffer into that or depth buffer you add that you know and after that you specify the depth town named controls your back buffer I'm sorry how many bits your back buffer is what are some other things you can specify you can specify or you can ask for how many bits for each component you want and one of the keys here is that is the ADL accelerated in that string it y'all accelerated I think I've written near me I didn't write i can't remember Ashley there is it a actually there is there's a QA about ATL 2 64 format which I would recommend anyone who's looking to opengl so it's a read and look at there's some caveats on how this works and it's probably more in depth and I can go into it in this setting but realize that it may not be obvious how it's choosing pics c'mon it's very logical and it's very easy to figure out once you know it but it may not be obvious first looking at it for example what it tries to do is try to match across any possible display that you pass it this pixel format so if i have four displays and i say i want this fixed will form anywhere but having two of those displays or not on an accelerated card at all i've spoken cards out of the junk bin put them in there it'll fail it'll say hey I can't accelerate this cuz I these two don't have GL renders on it so that's what I'm supposed to know why is the family I have my rage 128 I want it that's where the window is and so there's some nuances there as far as selecting displays and what you want to do if you want to win it to be draggable you want to see you want to make sure you do a truce pixel format for all the displays you could drag it across if you want to win or not be draggable you want to probably limited to the display that you're actually on so that's the nuances in hl2 pixel format but then it's real simple you call a chill choose pixel format you pass in hg g you tell us how many displays that you're passing it or list of hdds and you pass it the attributes so this case we're gonna say i'm on this HDD handle I'm sorry all of the age I that's my shorthand handle to handle to is used by sir GD handle and I have one monitor and I want to run on that monitor and here's my attributes when you're done with it you call HDL destroyed pixel format when you're done means when you're done creating it you don't need to keep it around until you're finished with GL you can actually create it a signatory of contacts that's the drawable and off you go and destroy it right right then so context next step in the process you have a pixel format you said I want to do RGB I want and have a double buffered I want to have a depth buffer to settle right now I have my pixel format for those displays now you want to create a GL context you're drawing which saved case we can encapsulate the GL state you can have more than one of these by the way it doesn't mean you guys have one of everything you can have as many of you really want to work with i recommend depending on what you do use go carefully at the difference between the digital format of context in a drawable you may want to clear one pixel format create a context and create a couple drawables with a saint Owen to its it to that pixel for my contacts or if you have maybe a window that you don't need any depth buffer I mean you have a different pixel format for that without a desk saucer and a context and it encapsulates that but if you have everything that needs the same thing everything needs a depth buffer everything needs rgba everything needs to be accelerated accuse me you can use one contacts and create multiple drawable select context but this is simple this is basically it pass it in a pixel format it has been null and use create a context and so pretty simple to get the context now check your errors and when you're done with it the actual on destroy it the key also is sex another thing is that current context if you have multiple contexts and you want to do that car and contacting you want to draw them more than one context one of the things that that I also find that people miss is a GL update context and it's not on the slide but I'll go over it a little bit if you're moving your window sizing your window showing your window or hiding your window you definitely want to do a GL update contacts it tell it let the AGL tell OpenGL how to reset the drawable and a reallocate buffers is necessary for examples you sighs a window we have to reallocate the back buffer there we have to make sure that we have a new back buffer this the right size of the window so we're not if not a good thing to do these updates without or do updates to your window without actually telling in the same thing if you move from one render to another we need to tell GL to not use the rage 128 and to use the voodoo so that you have on this other monitor okay drawable real simple set rawal you basically also draw was going to do is going to attach a drawable to a context you say i want to draw into this window basically and you can have five windows or you can have for example the patan standard cad program has three views top left front and the end a projection view what you could do is you could set up those three are orthographic those you set those three up that basically you have you know they're they're parallel projections you're going to do one context of those three and you have all of those parallel projections with three separate drawables you catch one you move your move your camera you draw that one attach the other move your camera draw that one move your camera draw that one then what you're going to do is you have a second context for the the one that has the projective perspective projection and you're in set that up as a prospectus perspective and you have that its own contact own drawable and you basically switch to that context that's current context draw that one and off you go calling swap buffers have when you're finished drawing for each one of them okay for SWA SWA buffers it basically tells OpenGL I'm done submitting stuff to you go ahead and draw so it's kind of the go ahead and take off and let your engine chew on this data see past 80 past a day pass data call swap offers it sends it all off the card and that's it absolutely not correct if they send it off to the car but it actually starts executing that actual person I shall frame the drall to the screen real simple is a a jail swap buffets with the context one note here is it does inclusively call GL flush which means basically terminates that scene for rendering and says go ahead and some finite time the feature I know this will Ashley execute a GL use font AGL use fine as a real nice thing to have a line first book the GL while ago and look at AGL use fonts and you know I'm the point can't quite understand I can't get it and then I thought it I fooled around oh this is really easy this is like super simple and this is great if I can put all kinds of data in my stuff I can go down render them on and put in my frame rate I can put out what it's doing I can put up state information I can do all this with by doing putting text on the screen in OpenGL without having to you know draw text to the screen which I'll talk a little bit about later but basically you don't want to try and draw text and OpenGL windows open GL doesn't know you're drawing checks and there's no idea and so it'll it'll drawl right over it or good text withdrawal over the OpenGL it's not designed to work in that fashion but atl you want I get an F num for Monaco for example and then I'm going to go use a create a deal unsigned integer which glu inch list base and that's the base of my base of a list of basically textures i'm going to have they're called gem lift 256 which generates 256 slots in that list I then call use font with my contact my fine idea the norm normal 9.0 200 0 is being a lift 256 which is the end of the list and the list base and what does that do that creates that basically takes that fun and draws it into all this hole faucet list so now I can go and I can say use my nice little function here which i use call list with with the string length into the list base and basically what i can do is i can wear the basis of the c-string and i can put a/c string to the display I set a position ladies this call this function tell what the spring is with a null-terminated string and use and what with the spring and then it's linked to the string and it just right to text out to the screen no problem so it's really easy to put text to the screen you can use printf you can use our s perhaps to format whatever you want and you sort it out you can put out errors if you want to the screen so it's real it real simple to do atl errors this is the differentiating from the GL error but a clr has a silly error page you'll get error in a gel error string real simple you get to you and we're going to do is going to get the error you're going to pass it in if it's not no arrow to an atl air spring and actually put some spring in a parsed format what i eat a lot of time to do is you do it to a debug string and so drops into debugger and then I'll conditional eyes that in a debug mode or not in debug mode so i actually don't get the debug strings on a final bill but in like i always want to be a I always want atl to tell me if this problems creating something when I'm doing my non debug build so there you go for a GL error it's pretty simple to use and it putting in part it right there we give you the voice of parse it they set up GL back to that sample code these sample code it's about five files six files and if you can pull apart you can tweak it around you do whatever you want with it it you know it's provided as is i think it does it does do a pretty good service you can just get it it's just one call to set up one call to take it down and off you go on your GL you don't have to do anything else i ported a couple screensavers from one of the folks who do windows 3d screen savers and i ported literally one of them in like 30 minutes using setup GL i should play something moved a couple things around so the wgl calls and that was it and i was done so it works pretty well um if you part of it was originally used for quake 3 and this is based on the quake 3 code that was work we work with them for enhance when windows in full screen the full screen is currently mac OS 9 only and I'll and I'll go through that a little bit right now now full screen on 10 is being implemented right now or is it is in development right now and we're going to provide that shortly vs feeding as a patch to 10 so for the we don't we don't have a way of getting full screen for opengl at this time that's something i would love to have had in GP for but you know we have to close the close the lid at some point and get someone to you so you can be developing with it today so but expect that really shortly I can't go obviously i can't give you definite times but I'll alert people on the OpenGL mailing list when it's available and so they can get it and they get downloaded and immediately after it's available i'll extend this to use the full screen section if you want to find more about fullscreen fullscreen applications we have our games on 10 session tomorrow that i believe it's tomorrow that will talk about some of the the option to know extensible screen game in hand of multiple contacts as a pause and resume in it and a sources available sample code at that URL it's really simple though and developer done a blog com / sample code and we have a real good hierarchy in the sample code it's really easy to find so use go to 3d graphics and you'll see any of our sample code for 3d graphics there so let's talk about using OpenGL I'll go through a whole section about how the basics to set up and use OpenGL is what how to set it up how did some basic transformations how to do some say using what the basic primitives are talk about alpha blending and talk about texture mapping a little bit okay so let's look at this code here this is through a GL the first thing we're going to do is we're going to set up a geologic routes basically the same thing we did before a GL rgba double buffered and none so this is saying I want a double bucket context so if slops actually going to draw into the bath and swap of the front a gba obviously red green blue and alpha channel for it and depending on what my resolution is depending on actually what the target is this does not set your display resolution or have anything to do with that kind of thing it just tells OpenGL how you want to draw pixel format and contacts all all set those variables up I'll choose a pixel format in this case is a different example of choose books or format in this case i passed an online account 20 what happens here is it looks across every monitor that you're looking at and it says can every monitor that is attached to system or every video card every graphic display device satisfy that pixel format if it can't this may fail so realize that's when the accelerated thing comes in again if you realize that setting a GL accelerator means that everything it looks at has to be accelerated for it to succeed it's one thing to think about I'll call a GL create context passing the format in that I got out of the pixel format obviously there's a there's no error checking included here but I would definitely say given the given the code for the error checking it's pretty simple to write in the AGL get air or AG el hierro strength and then i set the drawable basically i'm going to cast the p window to an AGL drawable again I can't stress enough that you want to use a window not a seagrass pointer for this pretty simple setup GL like I said simplifies your coding or you can use it rip it apart even pull pieces out of it you look at it as an example and I really don't care if whatever works best for you and whatever helps you in your development efforts in this case I call pre-flight GL basically if I expand this a little bit the gia the weight set of GL work is a GL info which is the structure yourself the structure is pretty simple to wit it's a height do I want full screen do I have to have this width and height this otherwise set of GL will pick out a window that kind of fits into your into your screen what works with that works there you kind of high pass in the GL full screw the GL info full screen to preflight GLS to know whether I want to use draw sprocket in this case to do full screen or not you know if I don't know all it checks for the existence of GL if I do it checks for also draw sprocket exists and we call that then I called build GL in this case I'm going to pass a pointer to a drawable a pointer to a contacts and appoint to a DSP contacts which may be nullify if I don't have a draw sprocket if I don't on full screen that could come back to null and I can pass the number of device so which screen on one on and basically passed my information in there and inside that information is the pixel format that scripture like we saw before and that's one call boom you're done and out of that you get your drawable in your context which is what you need to draw for GL destroy to yell real simple path the same information in it takes care of trudging everything down for you and closing everything out ok let's move on to transformation it's kind of a tough slide to go through and there's a lot of information on there and this is absolutely scratching the surface here one thing I look back and the years ago when i was in college i said man i really wish i had studied more paid more attention in linear algebra if your work if you want to work in GL and you want to do more than then you're fairly simple applications i would really look to make sure your linear algebra and your matrix handling is good there's a lot of simple things you can do without it but if we really want to for example if you want to write the next quake definitely want to understand how matrices work and how rotations work and help me help some offsets work and how how that interact with each other presents them that's a key to actually being effective in opengl programming but there are some simplifications to know there are some things you can do that don't require the super knowledge of linear algebra GL you look at i didn't mention glu yet glu is not a GL call to glu call it's a little bit higher level with every OpenGL implementation is also a glu the Glu it does some nice things for you and kind of build higher level instructions that rely on the GL instructions in this case you tell us where your eye is XYZ until we're the center of your display asst XYZ and you tell it up XYZ to what what the up Vector is so you can say I'm a zero I want to look at 1010 and you know 1000 negative Kensi and you can tell what your up vector is in your right you're rolling you don't have to figure out what I okay that's the right hand rule and I'm looking here and I'm moving around here did I tell it where you want tell what you want to look at and I'll set up and that sets up the Model View transformation it tell you it's basically sets as a basis for where your eye is relative to the weird center your screen is so if you just draw something now it'll draw relative to Center relative to zero in the screen which you can even move back and look at the zero if you wanted to also for modeling that's moving your eye for modeling to move your model you basically want to set up whatever you do whether it's with the cube of square or whether it's done and then Sarge and quake or whether it's a mile based model what you're going to do is you're going to use translate rotate and scale what that's going to do is you going to choose they do exactly they say one translates one rotates once scales and they can move your model around you want to apply this all the vertex in your model obviously and you want to realize that what order you do things in when your translate first and then rotate has different things and if you rotate then translate we can easily see that you have a square in front of you where you have whatever a car in front of you and you rotate and then you translate in that and local coordinates it may translate differently than translating and then rotating and so that's something to look at and some of the open field references talked about that talked about how to think about that in a way that works for people who have not done a lot of open jail program I mean it's not too bad you work through it closely it's pretty easy to do once you kind of get the hang of it one of the keys here it's one of the funny things I think every OpenGL programmer realizes there's more ways than OpenGL to get a black screen than anything else in the entire world everyone who's working OpenGL goes okay I got this figured out and I got it outside there and I checked it and I have my graph paper and I'm sat in my office and stared at my thing and I got this rolling okay run black let me look at something I look at my mind glu look at well so how do you know if could kill you look after all I mean you know your model could be off and you know in the next building over as far as you know I mean so there is my recommendation for all of it is too there's a ton of examples out there for OpenGL a lot of blood examples it does tons of things able to show you some examples and some of the stuff he's done and there is like five hundred examples in in our SDK use them build off of them look at how they do things moving small steps didn't don't decide like I did the other day that you want to display a movie on a surface that's rotating and deforming and you have your I move around at one time I lads us all at one time I don't want to add all this in one team pieces so you know work slowly look at look at your transformations carefully and learn what they're doing look at the different effects of the different transformations and you'll and you'll move forward quickly if you sit there and decide you want to write from crash you want to figure it all out I guarantee that you'll building a lot of lock screen for projection kill you perspective is really nice field of view I and aspect ratio in a near and far plane pretty simple I mean it just basically did using go from the fisheye lens to the telephoto lens and you know what how squished it is how round it is I'm it's like aspect it's probably going to be your screen aspect but you can do special effects so that you can squish things but changing aspect ratios and those kind of things it also tells you how powerful a lot of the matrices are in OpenGL because it allows you to actually change some things that you did you have a square window does not mean you have to have a square projection it can squish it it can stretch it they can do whatever you want you'll also is a example of how to do an orthographic projection thus you can do a parallel projection in its own that's wise instead of a frustum specifies a box angio viewport allows you to set the the XY location and the width and height of your drawable inside of your actual rendering area inside the viewport so that's something nice to do also you can move it around you move windows off there's other nuances there as far as like using a buffer wreck and AGL but is you port allows you to do the basic TL setup basic primitive points line triangle squads bygones real simple I say this is actually pulled out of a good Z draw a square code which you'll see later in its in its full wonderfulness set up a color call three vertices and end actually that's all as a piece of the square that draws a base of the square or a face and you can do them and it can be complicated for example the Maya demo you saw they did they don't use the OpenGL internal nerves kind of calculation they tessellate everything and they turn everything in the tri scripts so they have they basically their code you're going to see GNC of GL triangles or general Jodl tries prime Stephanie receive three vertices which color with the moment with was a texture coordinates or whatever but they're basically doing the same thing it's just a low-level drawing formative alpha blending alpha Bunny is real simple simple transparency and you what you do is get the enable button a blend mode it's again a state machine you can normally it's not enabled from your navel blend mode you can then set your blend function which basically tells what the foreground and what the background does and then you basically set instead of your color which you notice before I had set a color this time I set up an alpha value in that color so I'll use four components and last being the alpha value in the Alpha value says this is 50% transparent I do the same thing I did before so we got ok let me show two demos real quick and this is these are I have to say the idea what these demos let's make something really simple to show some of the things that OpenGL can do so so this is not supposed to be quake this is not supposed to be you know the next great amp because I'm what we kind of get is the spinning square you know this is a good place to start you're looking at something that really works you get you get a square and you can go from there so that's that's what spinning square so that's upsetting with note with no blending or alpha on why don't we turn on blending in this case basically I pulled that I pulled the code that you saw on the other monitor out of that and basically I just do an alpha blend with a square I mean it's not great but it shows the effect and you can do some cool things with it so we'll go back to the texture mapping slide now then go back to the PowerPoint so in reality I mean flat objects objects that have smooth shading don't really aren't really exciting as you saw in the demo this morning as in the keynote it's really a lot more exciting lenient with the texture mapping on there when you got a scene that it looks or looks well life like pops out at you that's when it gets real interesting so step steps and texture mapping how do you text your map the texture mapping is a little bit strange when you first look at on the mac did you kind of stand up that you supply this buffer to opengl and use that for a texture be kind of like well how do i get the buffer into the mac and all you tell opengl to use it and what's the difference between on kijiji world and a buffer so basically you needed to create and draw your texture and set your text for parameters and then you enable text streams enable text strings easy that's basically home from a code down there i'll show you code on the next page to create a text or an open jail the simplest thing is to draw anything you can into a G world so for example the use Quicktime i love using quicktime and you can use read any file format you basically want to save things as and you read it into a girolle then you would do what's called swiveling texture and swiveling pixels you have to actually put the pixels in an order right now until when with the pack official some that is one reason pack pixels is a really good thing to have but right now you have to move those pixels into a buffer that has them in order that opengl expects so for example most textures you may want rgba if you say your textures rgba you set up a buffer that just has a width and height x three components x 24 bits sighs buffer of rgba and then your extract component from your g world and put them into that box it's not really difficult to do there is sample code i'm not sure if it's up yet but it will be up this week that tells you how to do that and it's basically a 10-1015 line function it's pretty simple to do and it's not that slow either you can do some good stuff with it if you really wanted to be aggressive you can go and use a velocity engine and optimize that using the commute instructions to blast pixels in but for me I'm just picked the right leg pixels out and put them in the right order and move them over and it works pretty well so um the first part is that correct text parameters basically I'm these are kind of some standard settings for texture parameters I up some filtering for it so it knows how to filter textures and then here's here's the actual meat of it we enable texturing state machine again make sure we've been able to detect string GL text image 2d and this actually this is probably easier to look at in the documentation that it is on the screen Liz but the key here is basically i have three components i passed the width and the height and i tell us to know its RGB it's a 2d texture unsigned bites and I passes the buffer there is a pointer to my buffer which I've extracted from my G world put to put in the right format and that's the texture so that tells you what the texture is and can then you go the same thing I did before which is basically say hey I got to school with the face of the square make a quad but also added the injeel text coordinate and then it jail text corn is pretty simple texture coordinates are set up to be 0 to 1 so if i have a texture that's 512 by 512 it's 0 to 1 it's hard texture coordinates so assuming now mapping it to one single polygon it's real simple to set up when you're mapping to multiple polygons it can be not more complicated one thing you should look at is another glu function is a GL you texten function it's fairly complicated function probably beyond the scope of this talk here but it's something to look at look at some of the sample codes it uses it to this really can be a interesting function for texture mapping on more complicated surfaces that you don't want to calculate every single texture coordinate yourself Oh what else will say one thing another note on textures as texture should be powers of two our implementation right now specifies that texture needs to be power of two and people will say why do I get white textures and so I talked about quick time frame an image handling I talked to the pixels must be school Switzerland argb to RGB until pack pixel format is actually out and alpha channel is indeterminate equipped rom one key there is a quick trawl does not support maintaining alpha channels thus for quick draw you need to put your own alfin there is cases where you can read it in using quicktime and immediately blast it out with the alpha but yeah I'd be real careful you're getting doing the right thing white textures what could things going to do if you're out of system memory I think people see that was quick if you don't have enough system memory there you run it may run out of texture memory that's in the system that we need to sort expert into you can increase the vram or the virtual memory sorry increase the virtual memory on this and that will solve that problem it may not ever access that extra nganimate just sit there but it needs somewhere to store it so it can restore it if the card has to purge it you can have a text remote era for example you didn't turn texturing on so that didn't work or that was a lot of time actually or in this case that was referring to if you have 255 by 255 it's going to say i can't i can't texture this thing i don't know how to read the texture in so it's gonna fail reading any get a nice boy texture so what kind of texture demo i can have and this is again really simple one of the one of the things that i want the stress about these demos you can switch to the demo man thank you is that these are all built with the carbonized version of setup GL runs on that on 9 and 10 so i can run this application on nine or 10 and that it means is design what heroes make it real simple but using setup GL for both it simplifies to X amount of your applications carbon compliance subscale will allow you Carmen compliance and so I'll run this so this makes was released a little bit more exciting pulling the Maya face from what we had earlier J putting a marble texture on and this literally the code you saw i added was faced with the code I have to ask I mean really going from something that's really nothing just was a flat shaded square to something that's actually interesting to look at or reasonably interesting to look at it's not hard also you have we as a reflection the other production was just using an alpha blending real real simple stuff but there's something that that it's not hard to do if you haven't used OpenGL is pretty easy to get to this point can go back to PowerPoint so we going through that the last thing I'll cover some references big time if you're looking at OpenGL get the red book the red book is the OpenGL programming guide also if you want a reference manual I couldn't go back and forth if you can download the specification from ww OpenGL org or you can actually buy the blue book and by that as a reference depending on what you like is I think that's the OpenGL specs in PDF format and yeah if you want to print it I think you have to have a postscript level two printer to actually print it to the prism of the font handling but as far as the the programming guide is really critical to have and it actually goes through kind of step by step through all the pieces of OpenGL goes through a lot of examples go through a lot of kind of comp and moldings and show you how things work without just descending ascending function value where the reference manual is just a function references in alphabetical order the whole book is just function reference so they're both critical to have in different ways online WWE OpenGL or great place to go a lot of developer documentation a lot of white papers tremendous amount of things you can find there if you look around people ask any questions sometime and I go there and I searched around a little bit and I'll find the answer to our question that I may not have known just like somebody else's someone wrote mark chill guard had some great papers out there Michael goals have some great stuff out there steve baker st great stuff out there about some of I think mark kill guard has the 16 common OpenGL mistakes and almost everyone makes it's a good thing to read when you're getting going with OpenGL and also list on apple.com easy thing to do is just go to list on apple com search search for OpenGL and you through the OpenGL list subscribe to that asked questions we want the engineers monitor a list we try and answer a lot of questions there and that's a really good thing to get information in an apple OpenGL and i'll be in it when we have a speeds ready they'll be announced there when the full screen support is out there that'll be announced they're also so it's good things to look for okay I think that's about all I have oh ki roadmap OpenGL Mac os10 Dave Springer and talk about that that'll go into a lot more depth than I did and I'll talk about a OS 10 specific OpenGL OpenGL beyond game talks about using OpenGL for non gaming applications we're talking about handling multiple windows how to text your map and moving onto a surface and things you can do with it you don't have to use OpenGL you can use OpenGL for like a 2d sprite engine that would gets you a lot of special effects for free if your rotation gets you translucent so you can see all these things for free and you can take advantage to GL hardware arbonne geotech lead was going to talk about advanced optimization techniques following that and then we'll have the feedback form after the after lunch after and I welcome you all the please come to the feedback form tell us what we're doing right tell us what we're doing wrong and give us suggestions so that we can move forward okay question and answer and actually this lies I want to bring Bob beretta up on stage who is one of our OpenGL engineers easily the Guru so when you ask the hard questions he's gonna answer it so I'm Bob so if you have a question please come up to the mics and ask questions