WWDC2003 Session 201

Transcript

Kind: captions
Language: en
thank you again I'd like to welcome you
to session 201 which is Mac os10 open
jail and depth and I also want to take a
quick second then to introduce myself to
you the past three years I've
represented essentially the 2d graphics
technologies to developers and recently
with our emphasis on essentially
leveraging the GPU through OpenGL to do
things besides 3d and include things
like 2d such as our announcement that
was made in the graphs imaging overview
session where we actually showed through
using courts to D which is our to the
API drawing thrills in jail into an
OpenGL context it's been appropriate for
me to also start engaging OpenGL as a
technology so starting to being this
year I am really your official interface
with regards to questions development
issues on OpenGL for Apple so I look
forward to working with many of you who
might not know quite who I am or be able
to put the technology with the face so
let me kind of dive in and bracket we're
going to be talking about in the session
which is Mac os10 OpenGL and depth we
really want to accomplish sort of two
things during the session one is to talk
about macros tens implementation of
OpenGL because we have a lot of
developers who are new to the platform
they may be coming over from you know
windows may be coming over from unix and
the expression of OpenGL when those
platforms are slightly different than
what we have on Mac OS 10 so this
session is really intended to provide
the landscape to talk about the various
expressions of OpenGL inside the
platform because depending on which
framework for developing on it's gonna
have implications in terms of how OpenGL
is presented through that framework for
you to use then secondly what we're
going to do is focus on tips and tricks
and also introduce some new
functionality and OpenGL that many
developers have been asking for so it's
my pleasure welcome to stage Jeff stall
OpenGL engineer to take you through the
session thanks Travis
[Applause]
so again we're talking about OpenGL in
depth and as Travis said it's kind of a
multi-tiered approach to this session
what we want to do is we want to take
you from the beginnings of OpenGL for
those who don't know a lot about OpenGL
building on that with our API frameworks
that access open jail and then moving on
to some techniques and tips which will
allow you those who do know OpenGL
fairly well to gain something from the
session things they can use in their app
so first I'll start out with introducing
the OpenGL subsystem I'll then show how
to use OpenGL and talk about how to get
the functionality out of it I'll then
show some techniques for using the 3d
API and following up with as i said the
tips so let's first take a look at the
technology framework and I have this
ministry kind of a strange way that you
may not have seen before as far as
looking at OpenGL this is an application
on the top that access is OpenGL in two
ways on the right side of the screen is
the actual OpenGL access where it would
actually access OpenGL call the GL
functions on the left side of the screen
is the API that you have to use to get
at the windowing system or provide the
windowing system interface for OpenGL it
looks complicated as far as a number of
different API so what this actually is
it gives you a choice from the highest
level glut AP on to the lowest level cgl
api depending on how your application is
written will depend on what api you use
and it gives you a lot of different
options for writing an application and
access in the open gel functionality so
let's introduce OpenGL to you guys talk
about what is OpenGL then we'll answer
the question that Peter touched on in
his introduction session though to the
graphics track is why do you want to use
OpenGL why does I have a mainly 2d
application why would I want to use
OpenGL and when it's a 3d API right so
that's not something I normally would
want to use will talk about the OpenGL
state machine which is key to
understanding the OpenGL operations and
finally talked about the API and a
little bit how it's different than a lot
of other api's and figuring out what
actual functionalities available on the
platform so OpenGL in simple terms is a
hard hard software interface for
hardware it a lot of cases it
design and development parallel hardware
design and hardware and development its
platform agnostic which is why when we
move on to the interfaces those
interfaces are different on the mac o on
mac OS 10 d may have seen on other
platforms and it's asynchronous this is
something that Peter touched on in depth
in his presentation and it's good to
kind of REM ffice eyes that here because
what happens with an asynchronous API
you can actually issue commands the
commands at some later time will be
executed by the graphics processing unit
or GPU most developers are used to when
they call a command like a GL vertex or
or even a GL + GL flush to say that
command is executed by the time that
command returns in case of OpenGL in
most cases that's not true the GPUs are
so fast we don't see this a lot of times
we don't see that there's a lag but if
you issue enough commands you can
actually have the g be waiting on the
GPU and you can see isn't some of the
profiling tools but in any case keep
that in mind when you develop your
application you want to maximize your a
taster current a synchronicity in your
application issue the commands go on and
use the CPU to do other things easy
geometric primitives points lines
polygons so the basic primitive for
drawing you can draw lines you can draw
polygons made up of multiple points
fairly simple things we all understand
it also is a state machine OpenGL as a
stage set and that stays set until you
change it so if you turn texturing off
and you draw a polygon textfree ins
avacs going to be often it will not text
you if you continue to draw polygons
those will also have no texturing on
them until you actually turn turn
texture and on for example text Orion is
off when you first initialize the
interface and so a lot of people
initially get bit by the fact is why am
I not throwing a texture you're not
drawing texture p never turned it on so
something to keep in mind again when
you're developing for opengl is that it
is a state machine or remain set until
you change that state so the big
question is why should I use OpenGL
Peter showed in his talk that the GPU
development is increasing at a higher
rate than CPU development and even the
simple fact that the GPU is a very
powerful processor on the system that
you want to utilize to its fullest it's
not a good application
design in most cases to process data
with a CPU then wait for the GPU to
finish processing some data and then go
back to the CPU what you want to do is
use OpenGL to get a synchronous
processing so they're both working and
utilize the power that CPU power like
this we've measured in simple test oh by
the way for all this all these
measurements these are all g for
measurements so as of yesterday all
these numbers moved up a notch and I
think some of the developers we have
here just went down to a lab and tested
their application on g5 we're very
pleased and so huge increases in
performance above what some of these
numbers i may have here so we've
measured in simple apps 650 megabytes
per second across across the texture
upload across the bus this is like
modifying a texture that's four
megabytes just a thousand by and by 32
bit so that's like if you had a movie
there was a thousand by a thousand by 32
bits you can you can modify that at 200
Hertz 200 times a second you can modify
that texture play a movie at that large
size across the bus to the GPU every
frame real-world ability to upload
something in the neighborhood of 440
million triangles per second what that
means is it would say you're for it
you're single scene takes a hundred
thousand triangles you get a 1400 hurts
for 1400 frames per second in your
application or if you took a game like
do the kind of ubiquitous quake 3 which
is about 10,000 triangles per frame and
that's all they were doing was uploading
triangles you could get fourteen
thousand frames per second you can see
this is a lot of power also we have GPUs
these days with 20 mega 20 gigabytes per
second of bandwidth or more and this is
like if you have a texture on the GP
when you draw it's like drawing a fourth
a two thousand by 2000 by 32-bit 16 Meg
texture at 1200 times a second again you
can see the power of the GPU it's there
you should harness it OpenGL getting
back to the API OpenGL provides a large
powerful API that is good for 2d and 3d
operations as vertex and pixel program
for complete customization and finally
which is I think a really good draw for
OpenGL it is cross-platform and there's
lots of code samples but from Apple and
on the web for you to pad in your
applications after
so if you want a quick look at the
OpenGL pipeline we're not going to go
over this in depth but what you see is
the application is sending / midget
primitives like they're flowing points
lines and polygons they're sending image
data to the GPU or the to the OpenGL
framework it's going to do some
transformer lighting it's going to do
clip into the viewport you'll then move
into the rasterization step but that's
at that point you just a multi texturing
you apply the fog and then you do at the
end / fragment operations and one one
key do what's a fragment people who are
new to open shield understand a fragment
thing but fragment has a smart pixel as
a dot on the screen it may have
additional information of them in color
an alpha value have it have a depth
factor on those kind of things that are
fragments and that's why we get fragment
shaders vice pixel shaders and last is
the frame buffer blending to Brendan
blend with a frame buffer in the future
presentations about vertex ship vertex
programs and fragment shaders you'll see
how we take parts of these pipeline and
remove it and you can put in a
customized part of the pipeline so again
you can customize the controls and GPU
to your application so we talked about
state the OpenGL the state machine you
set the state so it does remain
unchanged we talked about does remain
unchanged until reset and one thing
you're also remember of state changes
can be expensive that is not to say you
shouldn't do any state changes and you
shouldn't over optimized for state
changes I mean you could spend months or
years optimizing so you do a few state
changes as possible as possible probably
not a good use of your time but also on
the other end you don't want to do
duplicates state change in large amount
of state changes per vertex or primitive
I mean I don't want to draw a polygon
change almost eight draw another polygon
changed almost a draw another polygon
change a whole bunch of state that can
be really expensive so try and avoid
down your applications in general change
from state draw some polygons change
from state draws and polygons and that
organization be much more efficient for
OpenGL you can examine states both
yourself and a programmatic level if you
want to examine it yourself the OpenGL
profiler is a great tool the OpenGL
profiler can pause your application and
at any point on any OpenGL call you can
bring up the entire OpenGL state and you
can look exactly what it sets so if
you're in that texturing case where
you're not getting any texturing
you could pause at the point you're
drawing that and look at the OpenGL fate
and say huh why am I not getting
texturing oh look texturing is turned
off text 2d texture is disabled thus you
can debug your apps and get a lot more
information about what the GPU
capabilities have and what they're set
for what they're set at with the OpenGL
profiler also programmatically you may
want to make decisions based on state
it's not always a good idea to do this
kind of if the state is not set set it
if the state's not set set it if this
states not set said it because that can
stall the pipelines think about it this
way we're talked about this being
asynchronous API so you have a command
you issue the command the command is
going to move down to the pipeline and
thats command could be a state setting
command what's going to happen is if the
next command following now that you want
to get what the current state is we're
gonna have to wait for that command to
push all the way through the GPU all the
way through the pipeline and then
retrieve the state to make sure that
we're actually retrieving a valid state
vector for you so realize that Gideon
setting state can be expensive but do it
once when necessary some calls at the
bottom you have a enable and disable for
set for enabling and disabling for
example texturing you have a GL get or
GL is enabled for getting some state
there and finally if you want to do a
large amount of state you can do a push
and pop attributes so the a OpenGL API
it is a procedural commands it is a
client server interface to get this a
synchronicity you're going to issue
commands and they're going to be
collected and sent to the graphics
processing unit and it's going to types
of commands our state commands drawing
primitives and manipulative buffers in
the most cases so here's an area want to
spend a little bit of time concentrating
on is OpenGL functionality and what that
means to you as a developer one of the
big misunderstanding is in OpenGL is
exactly what functionality do I have
when I'm running my program you may have
your design system that's tricked-out
has the best graphics card has
everything and your app may want great
but how do you make how do you detect
what functionality the end user is going
to have and that's where two types of
things come in both extensions and the
core API version number core API version
for OpenGL in general ranges from OpenGL
one point 0 2
1.4 on Mac os10 we only support 1.1 and
above we never supported one point 0 on
iOS 10 which just means that you never
have to worry about ever having that
case of one point 0 occurring in your
user base that's always gonna be 1.1 to
1.4 and usually it's not a case of 12
the driver come out or when did a card
come out or when did we rev a driver to
get what version it is it's what is what
is that actual hardware support so for
example if a hard birth does support 3d
texturing it can say it's going to be
1.2 or above probably in the hardware if
it doesn't support 3d texturing you're
never going to get to report a core
OpenGL version of above 1.12 the 1.2
OpenGL spec requires 3d check stream so
but what about a card that may say hey
on 1.1 but really can do some more
things than the 1.1 spec allows well
that's where OpenGL extensions come in
we support over 80 OpenGL extensions
they range from things that are Apple
specific like some of the things we did
with vertex array object some of the
texture range stuff that John will talk
about in the optimization thing some
things that we give you to allow you to
do as optimal mental a texturing pass or
vertex path as possible on Mac OS 10 or
the things that are like our multisample
which is for full screen anti-aliasing
is an ARB extension which is by the
Architectural Review Board in its
cross-platform and I've supported on a
variety of cards this scene this extends
the functionality above the OpenGL
current of the open show core
functionality we specified by the OpenGL
render how do we just text this which is
really what I want to talk about as far
as an application I'm an application I
don't want to just run and say well you
know 3d texture not support on every
card so I'm not going to run in anything
that doesn't support 3d texturing lots
not a good example or you know I really
wanted this vlog effect in my
application but that was a 3d text here
in since I don't know everything's in a
supportive 3d text here I'm not going to
even use the fog effect not on another
non good solution so what you can do is
there's simple checks you can do when
you start your application to determine
if thats 3d texturing is supported first
thing you can do is use a get string G
all version that will give you the
for version that's a string in a certain
format that's defined they'll be like
1.4 space and then there'll be some
additional vendor specific stuff at the
beginning of that's always going to be
the same so if you're opengl 1.2 or
greater you know you have 3d texturing
no more checking necessary comes back
and says hey I'm opengl 1.1 for whatever
reason you can then move on and look for
the extension for 3d texturing you can
do that by the getting getting the
extension string and then we provide
through the Glu the GL utilities API we
provide additional API to check for
specific extensions in this example I
used apple sense extension I'm checking
here for apples fence and this will tell
me if the fence is supported so I can
then in my code determine if I want to
do a code path that uses the fence or
not this is a really good thing or a
good example this is rectangle texture a
rectangle texture is a great extension
to use if you're doing a lot of image
text stream excuse me and it's not
supported for example on the rage 128
but you it simplifies your code paths a
lot if you can use rectangular texture
on some other GPU so you wouldn't want
to write everything as if it was a rage
128 you can use this this method right
here check for the texture rectangle
extension and then decide which code
paths you're going to use in your
application finally one thing you should
be aware of is OpenGL limit OpenGL has
limits of a car-dependent if you're on
the high end card you may have a
textured limits of 4000 pixels if you're
on a low end card it could be as low as
maybe a thousand pixels something to
determine if you're working with large
textures you may have to divide them up
you can use things like maxed exercise
right here in the Geo get integer and
that will get the texture size for you
so you can so again set your code up to
maximize you maximize the ability of
that GPU to perform function for you so
I want to point out at the bottom I
should have pointed out the beginning
this is a good time to do it I have this
blue line at the bottom of it it's a
sample code of carbon opengl carbon cgl
and coke opengl put that in the bottom
of a lot of slides what that is saying
is that's online sample code online
references that talk more about the
subject on the slide so instead of you
know taking notes on all these things
you can just go to this sample code and
actually has functions to do this the
other thing that's interesting about
this detecting functionality
saying it can be a large effort to put a
lot of checks in for a lot of different
functionality so what I do is build some
sample code it has a GL check function
in these three samples have it this
sample code will go through and for
every display and for every render on
your system it'll go through and build a
list of all the functionality present
including limits you can use it all as
is or you can extend it or reduce it as
it fits your application so I say you
look at that sample code look at how
that's done you need your model your
application directly off of that or use
the sample code directly in your
application as is that will help you
doing the detecting functionality so you
all don't have to write this the same
kind of functionality detection code
you're for every one of your
applications so let's show kind of what
the the detection of functionality
sample code gets and show you kind of
how well I talk about functionality for
extended functionality and core
functionality this is just a simple
OpenGL demo let me move this out of the
way and one thing I want to show you is
not not anything specific on the demo
but this information you probably can't
even read what it is but specifically
talks about OpenGL capabilities the
beginning is to exercise but the bottom
is a list of every extension or every
feature supported by this render on this
machine you can see there's a lot of
them so sticking to the core
functionality it's probably not going to
give you a very robust stab a lot of
functionality a lot of things you can do
with OpenGL in extensions you can use
the GL check which generates this
information to determine what extensions
are there in code your apps take
advantage of this when we go back to
slide so let's move on and talk about
interfaces interfaces are going to be
the meat and potatoes of getting your
application started that's something
that everyone here who writes in OpenGL
app will have to touch some of you who
already working with OpenGL may think
nad don't need to know don't need to
know this so I'm going to go through all
the interfaces and you might learn
something about if you're a carbon
developer you may hate that cocoa or
interface looks verse 39 so if your
cocoa developer and some carbon
interface stuff may work for you or cgl
interface and work for you so so that's
what we talked about in the interfaces
section all the interfaces share some
basic things these are the basic thing
so the windowing system has to provide
the OpenGL
member i said opengl was a platform
agnostic api what that means is there's
no windowing system calls in it there's
not any windows calls or any Mac os10
calls or there's nothing to say hey this
is the window I want to attach to that
window these interfaces provide that
they provide a pixel format which
basically describes buffering
capabilities so it's buffers like do I
want a depth buffer don't want an
auxiliary buffer or capabilities like do
I want full screen or do I want stencil
etc the context you can think of which
these provide is a state bucket the big
bucket of state and commands are sent in
going to be sent to that current context
you can create as many context as you
need for your rendering but this is
these will create your context for you
and finally the drawable is basically
equivalent to the window of view or the
screen it provides the size for your
buffers and actually the buffers are
instantiated when you attach to the
drawable interface is available there
are four interfaces we're going talk
about cgl cgl is a low level interface
its basis for all the other interfaces
it's for full screen only applications
but if you have an application that's
full screen and windowed you could use a
cgl interface for the full screen
portion of it and then use a different
interface for the windowed portion AGL
is the carbon interface to OpenGL so if
your carbon developer you're going to
look at AGL and use that to interface
with OpenGL and an NS GL or NS OpenGL is
going to be the cocoa interface to
OpenGL and finally glut is a very high
level interface that provides source
level cross-platform compatibility and
is used a lot for examples and in some
scientific community doesn't provide
that then rich of a UI set but for some
basic we want to test something out
works fairly well so again we've seen
this before you can see that glut would
be the highest level interface is
actually built on top of NS OpenGL view
NS OpenGL view is built on top of and
it's OpenGL context and pixel format AGL
is built on top of cgl and everything
else kind of sits on top of the pancakes
that way again your application is going
to pick one of the interfaces on the
left side and then access OpenGL from
the right side of the diagram so cgl
core OpenGL again it's low level the
basic interfaces of the foundation for
everything else full screen only and
let's talk about setting it up all these
interfaces has almost the exact same
setup code so if you're not to develop
an open tree all right now this is what
you're going to have to do to get your
opengl window on the screen it's going
to get a desired for the cgl for the
full screen you want to pick a desired
display mode do you want 1024 x 768 you
want something else capture displays to
make sure you do not modify any anything
else on the desktop or you know some
other application has or icon from the
desktop you want to switch the video
mode that you have chosen create a pixel
format for that specific display the key
here is a specific splice you're going
to pick a specific one display that you
want to want to render onto and make a
pixel format that centers on that
display and then you're going to set
full screen in this vgo so creates
context in that set full screen so let's
walk through the code example again the
cgl sample code here carbon cgl has the
cg almost exact same code in it this is
simplified slightly but if you really
want to look at this and study it please
download the sample it's on the web
right now and look at that I'll go
through the code here but I'm not going
to go through every detail in this
session so first we're talking about the
pixel format and this is what you'll see
in a lot of the setup code you see a
pixel format you'll have attributes is
actually defined things I like what
buffers you want to what capabilities
and here what's important to note is you
have a full screen attribute so since
the blind the full screen attribute will
tell cgl you definitely want a full
screen you could see GL could work with
off screens also with in this case we're
talking about full screen the other
thing of interest is that first two
attributes put together display masks in
200 doesn't mean anything right now it's
a placeholder but we put that in and
that's going to tell cgl what screen we
want to actually work on we then go down
and we get the main display for example
we get a display mode for the heights
and width and depth we want we capture
all the displays and we switch to
display mode those r cg calls those are
things that are covered in a cg e API
then we have one additional call that
Loeb may look new that's in the CG API
may have seen before that's cgl get to
see G display ID for OpenGL display mask
and what that means it's going to return
them to OpenGL display mask in that
after and fill it into that attributes
section that's going to tell OpenGL the
cgl interface what display you want to
use you call that you then set the pixel
format since you have the display mask
in there for
specific display create the context you
can destroy the pixel format right now
because it's not needed you could keep
it but it you can destroy it if you want
to set the current context and you'll
set full screen at that point your hob
and opengl context on your full screen
even you can draw to it fairly simple
AGL's the carbon interface and its
windowed and full screen support if you
look at the set up here it's really very
very similar to see GL you create a what
you can create a viewing window or what
ever since cgl used to screen but then
you're going to create a pixel format
and i'm gonna make a note here about
limits on multi screen pixel format so
something that it's probably more
complicated we want to go into for this
session if you have specific questions
about it for your apps we can talk about
it afterwards but i also point you to to
check notes there AGL choose pixel
format the inside scoop in the correct
set up of an AGL drawable both of those
have a significant amount of information
about choosing 60 formats and how it
contends with multi screen displays he
chooses a normal pixel format should
normally have them to pick every render
it possibly can support and you'll be
able to drive the window between multi
screen displays there are reasons you
may not want to want to do that in some
cases the reasons that you probably want
it that way so for just a normal app you
would want to just choose an open pixel
format but let it choose a support all
the renders and then you get the ability
to drag between this place he then
creates a contacts attacks a drawable as
we've seen before so the code example
for windowed basically the attributes
we've seen the action of these before
their AGL attributes instead of cgl in
this case double buffer depth those are
similar to what we saw on cgl you then
choose the pixel format you then in this
case I chose them some checking here if
I created a pixel format and then create
a context if i create the context I then
set the drawable and if you notice the
get window port to the window what
that's going to do is actually going to
use the windows that I've created and
the normal carbon routines as the
drawable and I'm going to set the
current context and then you can draw
into it with opengl one thing the the
bottom of that shows sometimes people
ask about about BBL sinking normally for
in mac OS 10 we do not think a display
or sink the open shell drawing to the
VBR or limit the opengl drawing to the
VBL so what you can do with with this is
used to set in is your call that's in
almost all of the the api and now
to sink to the VBL here in this case you
call a GL set integer with the context
and you want to use the swap interval
and set that to one and that means hey
we're going to limit to the VBL sink so
now let's move on to HDL full screen in
the AGL API you can also do full screen
inside of that API itself this looks
pretty pretty much the same but what's
just highlight the things that are
different it's only about three three or
four lines that are actually different
here first we've added the full screen
attribute to the pixel format so that's
a missing hey I want a full screen not a
windowed window pixel format we then
we're going to get a main device so we
need a device to do full screen you need
to tell it where did the full screen and
AGL's a little bit different than cgl in
the fact that you add you put the
display into the create pixel format
instead of in the attributes so you put
the display yo Scott one display to draw
two and the attributes to create a pixel
format and then instead of setting the
drawable do a set full screen fairly
simple so this is really really simple
stuff as far as how you set up OpenGL
you can get running with OpenGL
depending on what API you pick in a
matter of minutes let's talk about an NS
OpenGL honor and it's open NFC LNS
OpenGL it's a cocoa interface very
similar to the other interfaces we've
already talked about two ways to use
cocoa and NS OpenGL first is the NS
OpenGL view subclass we already have
provider to NS OpenGL view in the cocoa
interface and what that allows you to do
is basically encapsulates a contacts on
a fit pixel format already in it and
give you some basic utility functions
handling some of the bookkeeping
functions for you and so you have to do
very little work there are some
limitations to it for example if you
wanted to have to context that work with
one view it's possible to do in cocoa
but the NS OpenGL view subclass will not
allow you to in that case you would have
to roll your own NS OpenGL view so then
go back to the NS open trophy you
subclass the last point on that is that
it's basically you can build it via
interface builder which I'll show you in
a minute and it's fairly simple to hook
this into an application but what's say
you have an application you want a
special case it for example you want you
want a a context it does let me think
multi samples you want to on Andy
alias context in a non antialiased
context and you want them in the same
view and you want the kind of switch
between the two without any flash you
don't want to actually replace a view
all you're going to do is not render one
in the next frame you're going to render
the other you can do this fairly easily
by just replacing the context interview
you're not going to tear the view down
you're not going to you know we have a
big white flash or black flash of
nothing being drawn you're actually
going to replace the context but this
would not work within its OpenGL view
you'd have to roll your own and it's
open G of custom in its open gel view
based on the NSA and it's view subclass
using in its open show context and NS
OpenGL pixel format this lip you seem
daunting for some people make sure they
cover all all the cases to simplify this
we provided some sample code to custom
cocoa OpenGL sample code which went up
this week is on the web now for folks
who want to roll their own it shows you
basically and a template that you can
use directly and you can modify it as
needed and actually a great starting
point for that I'm not going to go into
detail here but that sample code I want
to point out is available and for your
use today so let's talk about NS OpenGL
view and using that created three
interface folder you create your window
you create your view and maybe you use a
custom view or an OpenGL view and you
drag it into your window allowing that
to have the clan you create a subclass
Venice OpenGL view having that class
manage the view creating interface built
or Zen in code what you're going to do
is you're gonna have to you override a
few of the methods the Venice OpenGL
view first one is a knit with frame earn
it with coder depending on whether you
use a custom viewer OpenGL view you're
going to you can / I one of those you
can do things like say your set your
pixel format up there if you didn't want
to set it up an interface builder itself
then we have a new routine in Jaguar
called prepare OpenGL you can even kind
of write code that uses prepare opengl
i'm sorry for panther uses for fair
opengl in panther and then uses your own
prepare opengl in jaguar without having
a problem so what I do in prepare OpenGL
is initialize all my OpenGL state one
call to do that in the right place if
you don't have it if you want to write
an app that runs on both Panther and
previously what you can do is in draw
rect conditional eyes like an
initialization variable and if it's not
initialized you call your prepare OpenGL
routine this would work on on both os's
or
both OS versions reshaped call someone
you may have been noticing that there's
a reshaped Colin in this opengl view and
here i'm not recommending to use that
reshaped call you can use your free to
use a reshaped call if you like it's not
as no problems using it but my
recommendation is it's fairly difficult
to write code that optimizes reshapes
and of interval has less overhead and
just reciate handling any reshape or
resize in your draw rep in your drawer I
can easily check the view size and call
GL viewport to reopen to reset the view
signs if there's been any changes that's
kind of the recommendation for us for
simplicity and for working across all
kinds of code classes or all for working
in alcohol situations just do handle
anything that needs to be done for
reshape in your asshole draw our class
update update routine is called in about
4 cases and there's a QA that will just
went up about updating OpenGL context I
suggest you all when you're looking into
update look at that QA and it describes
all the cases for that update needs to
be called in the cases that need to be
call our things like display
configuration change or if window could
be dragged and change render the idea
behind update is update takes care of
render changes for you so if you have
two displays and someone's going to drag
your window from one display to the
other at some point it's likely the
renderer will change into a second
second renderer or whatever your other
card may be in your system update needs
to be called in these cases to make it
happen normally in Venice OpenGL view
you probably just want to ignore update
it unless you want unless you need to
track renderer changes you just need to
make sure it works right it'll happen
behind your back update will be called
taken care of you won't need to do
anything if for example in some reasons
like in some of the examples that I have
I want to show what render rahman i want
to update some text actually what's up
with sub class or overriding an update
method but you got to make sure you call
the super update first lastly draw rock
draw rocks where you're going to do your
work I'm going to handle our resize then
I'm going to do a lot of drawers there
I'm going to draw the content in draw
rect finally animation timers so if you
want to do animation you can use an NS
timer and the only note I would have
other than
NS timer uses you want to use both
tracking run tracking run loop mode and
and normal run Lou and default run loop
mode event tracking runnin loop mode
which allows you to get the updates in
during the resize so I'm going to take a
departure here from what normally folks
would do with a demo and I'm actually
going to create some code so we're going
to do we're going to go to Xcode we're
going to start and we'll create a new
project and we're going to make it a
cocoa application and show you how
easily it is to create an OpenGL demo
live on stage even when you can't type
well so first thing I'm going to do is
I'm going to look at the nib file and
then the standard nib file you get has
just this one window in it what I'm
going to do is I'm going to take a
custom view I'm going to drag into the
window and umbria I'm going to resize
this the entire size of the window then
I want a class to control that custom
for you so I'm going to do is move in we
mentioned that and it's OpenGL view is a
subclass of NS few then it's open govt
you and I'm actually going to subclass
that with my own class my open G of you
and that's fine for the name they're
going back to the custom view get some
information on the first thing I want to
do is make sure when the window resizes
that it actually adjusted sighs I'll do
it that way and then finally I want to
make that a custom class using my my
OpenGL view like that let's use
interface builders ability to create
some files for that it's going to
automatically create those two files put
it into the demo right there and then
we're going to save this and we're in a
quit interface builder if you notice now
we have two additional files that were
created in our project by interface
builder we're going to add some code to
these files so because my poor typing I
don't want to type all all these codes
I'm sure would make mistakes but I'm
going to add some simple things like
headers some variables and that kind of
thing so first thing we're going to add
it was going to add the OpenGL headers
the OpenGL framework GL GL EXT and glu
I'm going to add some member variables
over here and what that's going to do is
that's going to add an initialization
variables can have a time
a flag on animation a time for the for
the timer and then some rotation values
nothing no opengl values here i mean
this is just things you can do for for
doing some simple animation to make the
the demo a little bit more interesting
and here i'm going to add i'm going to
add the functions i'm going to override
when they have a pixel format updated
projection update my modelview matrix
i'm gonna do some animation right here
do my drawing routine this is the
prepare opengl i talked about we have
our knit with frame we have an awake
with nib to set up some variables so
that's all i need in there in the opengl
view class we're going to where you're
going to add first thing we're going to
add is the rotation drawing code this
code is just some call it does some
things to actually calculate some
rotations to spin some things around to
make it look interesting and then at the
end this is the drawing code right here
this is the color this is a vertex to
draw some quads and what we're going to
so this is the actual to opengl drawing
code and then I draw a line around it
around the cube what's this lets loose
under all the cube this data up here is
the actual vertices for the cube their
notice they're all ones and zeros is
just a unit cube we talked about pixel
format this code right here actually
defines a pixel format this looks very
similar to the example I showed it's
going to go windowed pixel format its
double buffered and I'm going to add a
depth buffer here so it's real similar
to what we talked about in cgl and the
AGL these two functions i added here
update projection updates my projection
so I saw actually get a projected
spinning cube and this actually updates
the world especially the rotate call
here from GL to actually rotate the cube
now I'm going to add the animation timer
so this is what we talked about before
this is the timer it's going to get some
time do some do a difference here if I'm
animating I'm going to spin the object
then I'm going to call that draw record
teen this is the actual spin the object
of some math to make it look like a nice
pretty spinning object and finally
this is the four functions that you
actually need to override a draw record
team what's this going to do is going to
handle the resize right here which is
what I talked about handling and draw
wreck it's going to do the anit at the
very beginning if it's not been done
it's going to do a clear it's going to
draw the cube and then it's going to do
the flush of the flush buffer depending
on what situation i'm in prepare opengl
some opengl setup code right here and
I'm again this is the Coco version of
that swap interval 4bbl sinking very
similar to the HCL version an it with
frame is very simple all I'm going to do
is create a pixel format we've talked
about and finally the awake with me i'm
going to use this to set up some values
and set up a timer so if i didn't do
anything wrong we should be able to
build this and run it
and so this is an opengl spinning square
that resizes handles updates correctly
handles the the full screen zoom very
easily and so that's all it takes to do
an opengl app and i put a square in here
but you can do any any content you want
the point is it's really easy to get to
the point we actually can draw your
content and all this code that I used
here is based on the sample sizes on the
website there's a cocoa opengl sample
that's really simple to use and you can
just take that rips the guts out for the
drawing code and put whatever drawing
code you wanted we can go back to slides
down lastly I want to talk about glut
glut as I said is a source level
compatible across platform api it's a
limited api but it's fairly simple to
use so it works really well for doing
examples is another another ideas if you
wanted to do example or test some things
you could use glut set it up quickly and
do it that way and it works across many
platforms it's callback faced the setup
is fairly simple you initialize glut you
create your windows you set your call
backs to the things you want to do and
you call glut main loop don't expect
glut manian loop to return so don't put
any code past it they're probably exit
without returning after a different code
path here's an example of what your main
and glut works like we're not going to
talk about the specific callbacks I just
wanted to show you an example of it what
you have is you have the anit function
you have the window create you set the
display mode similar to pixel format you
create a window you actually can then
initialize some OpenGL state if you need
to and then you set your callbacks
realize that a couple of a callbacks are
apps based vice window base for example
the idle function you get one of them so
if you set an idle callback you have one
Idol callback for your entire
application where for example the
reshape functions on a per window basis
whatever the current window is so that's
what some glut code looks like and now
there's a lot of glitter examples also
on the web and on our site so let's talk
about some OpenGL techniques here these
techniques are things you can use in
your current applications to either
improve them or some things to make more
content that's more interesting than
just having your spinning square first
technique is some texturing they'll move
on to some fonts talk about having image
it handling images and then movies
in this section in general you'll see
that i'm going to talk about the
technique and not specifically show you
every nuance of the code behind it again
there there's samples for all this on
the web I want to talk about giving you
an overview in a context to work from so
you can look at the sample understand
what it's doing and rather have you work
through the code at your own pace and
ask questions on the mailing list or
whatever if you need to after the
session so first text string we can do
texture into two different directions
one will be using cocoa and one is
carbon using QuickTime first for cocoa
we're a texture from a packed 8888 or
1555 a RGB buffer what that means is
going to be alpha red green boob pixel
format it's going to be eight bits per
pixel or 11 bit allison and five bits
per pixel or poor components are you can
allocate a text texture so for example
you want to do that you allocate
exercise buffer using new pointer malik
whatever your routine of choices that's
going to the exact size of your text to
your reading in you can create a G world
from the buffer with a cutie new g world
from pointer as also the function is new
jew or from pointer use whichever one
you'd prefer they're actually the exact
same routine this point what this does
is create a buffer you can actually draw
into using QuickTime and quick draw that
does not have padding on the end of it
so you can text you from it easily you
can draw into the G robe with whatever
content you want whether it's an image
whether it's a movie whether it's just
lines and circles or text or whatever
you want to draw you draw into it you're
going to dispose the cheer old if you
want unless you want to draw some more
because you don't need to keep it around
all you need is the buffer you created
initial you don't need that G world to
text you from and then you're going to
texture from the buffer you lose
standard OpenGL texturing techniques and
you and understand that Apple pack
pixels will be used here it's an
extension that's on every single Mac
os10 implementation so you can count on
it being there and it'll end the texture
formats are either unsigned int 888
reversed or unsigned short 155 reverse
and what that does it tells what the
pixel format you have natively in that a
quick draw format is to use for text
stream so some code fairly complicated
or fairly busy looking not cotton Ashley
complicated and but I'll go through it
and we'll talk about it and then we'll
show a demo a little while using this
code
so get graphics importer for file in
this case is going to you have a file
descriptor an you're going to actually
try and load a file in you can get
natural balance for that which gets the
size of it you then can allocate a
handle the size of the image descriptor
here to get the additional information
on the depth of the thing where I get
the depth part of the image of Scripture
I then get the height width out of the
image information I then calculate a
stride to use well for convenience later
and an allocate a new buffer that new
buffer is going to be my texture I'm
going to use it actually for texturing
QT nude reworking pointer as we talked
about now it's actually going to create
a G world from that buffer that you can
then use to draw into with quick draw
and or QuickTime and then you can text
your out of using open GL graphics
importer said she world graphics imports
that quality we're going to do lossless
quality and we're going to get the pics
mass loss two pixels and we're going to
draw in it use the graphics importer so
this basically took the contents in that
file and drew it into that G world which
in turn was drawing into your buffer you
get unlock the pixels close the
components for the import and actually
going to suppose the G world dispose the
G world at this point but you don't need
it all you need is that buffer you
created and then later on when you want
to text it from a urine scald GL text
image to D notice I use a rectangle
texture with you mentioned in brief
earlier which allows you to text you
from non power of two images and I do a
switch on the depth of that image and
determine whether I'm gonna use the one
five five five or eight eight eight
eight eight pixel format that would be
kind of the overview of how to texture
from a G world so moving on to texturing
some cocoa using NS image and in this
image and it's bitmap image rep so first
in this case we're going to texture from
than 88 88 RGB a format which is what
you're going to see from core graphics
or cocoa or to create a texture size NS
image so you create an NS image as you
would normally we're going to lock the
focus on this image and we're going to
draw into it we're going to create a
bitmap image from NS bitmap image rep
from the NS image usually I do the focus
view to create that so it's fairly
simple to do but exercise will be that
bitmap sighs you create and then you can
text your directly from the bitmap data
in this case rgba and
using the unsigned byte format so what
if code for that looks like a little bit
shorter a little bit simple so if using
the cocoa a little bit less work to do
here the NS image a lock an it then you
get the lots of focus for that image you
draw whatever your content would be
there you create the bitmap or you can
me back up a little bit when you create
the NSA magine created and it's an image
from a file in that case you would not
really be drawing just a lock focusing
and you'd create the bitmap you'd
already have the content the creates a
bitmap you unlock to focus if you'd only
need to have it lost anymore you get the
size from the bitmap and then you call
text image 2d texture rectangle again to
handle any size image and you're going
to use the RGBA and unsigned byte for
that so bitmap released image release
again this is in cocoa same thing we
showed in carbon fairly simple to do
this is areas of OpenGL where you have
to interface with the operating system
to handle that image and this is things
that opengl does not have built into it
so there's two areas you would even adds
interface there so I'm taking the text
design we can extend that to drawing
fonts and if you want to use there's a
couple ways to do drawings fonts first
on a per character basis there's things
like a GL use font I also in the cgl
example i wrote a cgl use font once it
works very similar to a GL use fonts if
you're not using a GL you can get that
per character bitmap font good for as
you of what you saw in that in a
previous example for putting up text
like that just kind of debug text
texting you want information but it's
not optimum bitmaps are not real fast
especially redrawing the bitmap every
frame is not a good idea so what can we
do there's two options here one I
mentioned here and one will talk about
at the end if we have some time and show
you a quick demo on that first if you're
doing a purse-string textures or text
and you want to store them in textures
that's a fairly simple thing to do some
tips on doing this is limit your updates
every time you change that texture you
re-upload the texture if you keep your
text your constant through the entire
application or you have some some things
that's limited to when the user response
to something update only the string at
that point updated texture at that point
and you limit the amount of updates of
the texture onto the graphics card using
premultiplied alpha for textures and if
you know if some
you aren't familiar with premultiplied
alpha we can take a little sidebar and
talk about premultiplied alpha
premultiplied alpha is something that is
not a lot of people when depending on
where you what your background is in
graphics yeah you think of it thinking
this term so don't think in this term so
for people don't think about
premultiplied alpha is gonna be really
good to use in your application it's
alpha which is already multiplied
through your pixel in your color so a
50-percent gray non pre multiplied red
one point 0 green of 1 point 0 blue of 1
point 0 alpha of point 5 premultiplied
point five point five point five point
five so that gives you the ultimate
alpha is already pre multiplied through
why use it it's simpler and it's closed
on the / operator so over is basically
the compositing operator if you
composite something over top of
something else you get a closed function
if you don't use premultiplied alpha and
you take two images and you composite
them what you get out is pre multiplied
so then you try and use this image with
something else well this is prima know
what was the first to know well what
does he's pre multiply all the time to
breathe multiplied images you get pre
multiplied out two more pre multiplied
images you get pre multiplied out take
the results of those to put them
together and you get pre multiplied out
consistent across the board easy to use
you can use it very simply the only
change in OpenGL to understand is the
blend function changes non-free
multiplied and people are doing blending
out here they're probably used to doing
source alpha on look on the source
component in this case you'd since you
know that the alpha is already
multiplying through your color you'd use
gl1 and know that the color already has
the alpha value in it that's the sidebar
and premultiplied alpha we have more
questions about it we can talk more
about that later back to drawing font so
the last thing we're the if you want to
have colored text one or color-changing
text instead of putting the color in the
text itself put it in the putting the
polygon use a polygon for alpha for
blending use the polygon for for color
eyes and pond springs if you want to do
that so it's really easy to get high
quality fonts into OpenGL through
textures
let's go to a quick demo on that so this
is my cocoa opengl example which is
something also available on the web I'll
move nala till you leave the square
there and i'll bring the so this is the
same thing you've seen before probably
too hard to read it's not really
important what the text says but how how
it operates on the frame is more
important this is using a very very
simple NS string texture class that uses
exactly the techniques we showed for
texturing and handling strings and you
and creates simple strings that you can
easily update scale they composite very
nicely over top of each other you can
premultiplied alpha and it's set up in
such a way that if using cocoa go and
download the sample and just use a class
directly in your applications you pass a
string and it creates a texture for you
and you can draw with the texture and go
back to the slides so let's talk about
handling images images can be displayed
in a number of ways last year I took a
long time in be half an hour of my
secession talk about image handling
there's a fairly all-inclusive sample
out there that shows you how to handle
images and drawing images and all kind
of defer to that for the actual working
code of handling every single case but
let me go through the technique here
involve so people who want to put images
especially people working with the 2d
world one--yes opengl this is the
technique you want to use skit images on
on your on your screen first the
simplest thing to do is use an
orthographic projection if using 2g 2d
and you're you're actually compositing
things there's no reason to use a
projective projective projection you
actually can just use an orthographic
projection their line everything up set
everything to a pixel kind of format
into your window so you actually address
things just in window coordinates you
can scale the polygons as appropriate so
if your image is inside a polygon you
should ask this scale a polygon
appropriately to draw your image three
options for handling images that are not
a power of two sides which opengl
textures are things want to be first
thing you can scale to a power of 2
which means that if your texture is
let's say really spin short of a power
of 2 and really tall that's greater than
a power of 2 you scale it to a big
square and then when you actually draw
it back into the polygon it's the right
aspect ratio it'll unscalable
data in this case but for a lot of
people that maybe work very well for
what you're what you're what you need
second thing you need segment two power
of two rectangles you actually can slice
the image up in place you don't have to
have supper textures you take one big
image buffering you actually slice it up
use different texture pointers and you
can use this to tile it across any set
any constraints for that you want a
power of two textures and then finally
you can use the texture rectangle
extension that we mentioned already to
do non power of two textures makes
things real easy understand that the
texture rectangle extension uses image
coordinates for textures rather than 0
to 1 normally a texture is 0 to 10 to 1
horizontal and vertical if you add a 250
by 300 texture and you were using text
rectangle be 250 by 300 for your texture
coordinates let's look at some sample
code again the sample codes available
today to look at and download and you
can look specifically through this and
we're going to pick an image and there's
a lot of the sample code shows a lot of
the different techniques for example you
can use a non power to texture texture
rectangle or you can use in this case
you can tile it for a qatal the thing
and set the max exercise you can look at
the differences in how it would handle
different images in this case I'm going
to tile up to 128 k tile and this is the
image itself and this is using opengl
i'm not sure if i have a tear yeah i
have a tear here and that probably is
relate relating to the fact that we have
multiple displays synced up and we're
not actually sink to the VBL of the
projector but normally in your
applications on the screen you wouldn't
be seeing the tearing but this is a very
large image this is 2700 by 1700 s is
about twelve megabyte image no problem
handling the rotation you can easily
rotate it you can easily zoom in very
quickly using OpenGL and have OpenGL
manipulate the image you know you rotate
it at high speed and rotate and zoom at
the same time so this is using
everything you get with open shelf for
free no problems let me rotate this back
up to kind of straight and show you what
opengl is doing behind your back those
green lines or the actual textures is
using your the actual texture that it
that it used so if i look at like the
corner for example that made
interesting and i zoom in I can actually
see that OpenGL made some small textures
and slice this image to very two
textures that were power of two
necessary to texture without the GL
texture rectangle extension so that's an
example of using OpenGL texturing and
again let me zoom in zoom the image to
fit the window and rotate it and just so
you know this is again a twelve megabyte
image and it's a texturing ad it's
getting one hundred and sixty frames per
second without working real hard of
performance so you can see that that's
100 60 frames per second updating that
twelve megabyte image or texture we go
back to the slides now so OpenGL
handling images works great so it's not
about playing movies playing movies with
OpenGL the setup is very similar to the
carbon set up to solve before you can
use QuickTime as the API to play the
movie and you need standard quicktime
set up techniques and you can use this
in a cocoa or carbon application one
thing you do need to do is know when
clicked on finish drawing a frame of
your movie what you'll do is use the new
movie drawing complete upp and you'll
create a callback basically that says
hey I'm done with drawing a frame at
that point OpenGL can check to see if
the frames been updated if it has it can
texture from the updated frame same
technique to just use an opengl image
and update the frame on the screen so
really what you're doing is you're
drawing a sequence of images and
updating when you're told to by
QuickTime that's the simple technique
there's nothing more involved in playing
movies on the screen some people when
they sit back and think about will
realize if there's actually two points
of synchronization 110 when quick times
done with the image you can use it in
one when OpenGL is done with the image
it takes a little more complicated code
to handle both those synchronization
points many applications will do fine
updating their open GL texture when
quick times done with it and not worry
about the second sink we do have a
sample the open geocomposite or the lab
that shows creating a custom codec to
actually sink at both ends of the thing
for things that people that need
specific thinking and very fine fine
control of the movie playing and then
we'll use GL text image 2d & onlys a
different routine GL text sub image 2d
to actually update the movie when we're
only updating the part of the movie that
actually changed and we'll go to another
demo of this again this is sample code
is available on the web
opengl movie and i will grab something
you probably seen before and this is
again it's basically drawing a new frame
every single time i think that the word
that the movie tells it has a frame
update and you can see right now i'm
getting about 250 260 frames per second
of opengl drawing updating the texture
to race a quick time update this extra
for a 24 30 frames per second movie so
the point here is that you can meet with
opengl easily handle a texturing
capabilities for a single photon stream
of multiple foot time stream stream so
you'll specs on movies get moving to the
screen and at a high speed it's not a
bad thing since integrations use opengl
for your application and manipulating
the polygons that free I can draw that
just as fast as living water spinning as
I could don't wear on the screen size
suppose print ladies to apply what go
back to slides so find the final section
of the presentation is some tips and
we're going through three things that a
lot of developers run into and then can
help you develop your applications help
you to polish them up or understand
what's going on behind the scenes a
little bit better first we'll talk about
shared context and we'll talk about full
screen any aliasing finally we'll talk
about render to texture a much requested
feature that we've added for Panther
first shared context you have a lot of
windows you have a lot of different
stuff on your screen you have a lot of
textures you may use display list you
have vertex programs fragment programs
but you only want to write them once or
load them once you don't want to have to
load the texture into every single
context if you need share contacts to
alleviate the problem with loading
multiple textures texture objects vertex
programs primary programs display list
and a vertex array objects all can be
shared between context the other
contexts state like is texture and
enabled or not it's not shared so it's
just those objects and the associated
state with those objects the trick here
is it's the same virtual screen
configuration which sounds like a
mouthful and kind of in some cases gets
tricky there are two ways to avoid
worrying about virtual screen
figurations and sharing contacts first
create the same pixel format create a
single display pixel format or share it
with other
with other context of the same pixel
format so first if you're doing full
screen or if you know that you only have
a single screen system or you want to
constrain your windows to a single
screen take to creat that pixel format
using some of the techniques we chose
for the full screen section only support
that one screen and you'll be able to
share no problem second is you can
create a single single pixel formats and
share across contacts with a single
pixel format full screen pixel formats
and window drawables are also something
new for Panther for panther and for a
pre Panther who would trade a full
screen pixel former and then we were if
they try to attack a full screen pixel
format with the full screen attribute to
a windowed drawable we would fail on
that which a we relaxed that description
basically made that full screen
attribute a additional constraint on the
pixel format but when it attach this to
the drawable it's an optional item so
you can create one pixel format this
full screen and you can crash to your
window drawable you can manipulate your
thing in a window like maybe a keynote
kind of kind of application manipulate
your slide and you want to go fullscreen
well when the user shifts the full
screen you actually use the exact same
pixel format and you can actually create
a full-screen contacting slow contact
and creat that in full screen attached
to a full screen drawable rather than
having to recruit rip tear down and
recreate everything this will help your
code simple and simplify your code path
looking at some context sharing code for
this example is an example of using a
window to in full screen drawable and
sharing the same pixel format first
thing we do is create a pixel form of
fullscreen can create the same pixel
format without full screen we're going
to get the main device to show you that
we great both both choose pixel format
uses the same device in both cases and
you'll notice that the second create
context call the final parameters these
AGL context of the first context that
shows you the code was sharing a context
is going to be like in this case it's
too will share the read the object
resources those five things we talked
about there's some examples of this also
in some of the samples on the web full
scene anti-aliasing let me google ask
about how is full state how do you do
ssa or full scene anti-aliasing on the
macintosh it's not supported I don't see
a full screen and immediately is button
on a control panel well what full
screen any aliasing does is it actually
is using to our multisample extension
which is a standard way of supporting
Oakenshield full scene anti-aliasing I
say scene rather than the screen but
it's on a per window basis not a per
screen basis so you can have one new
window that's anti alias and one no
that's not an ileus the extension has
specific details and how it works but
let me go and say the setup of it is
pretty simple you're going to basically
create a pixel format near add a couple
items to your pixel amount of samples
and a sample buffer to your pixel format
that tells you that you want to do full
screen anti-aliasing then you're going
to enable our multisample with the
multisample ARB GL extension and then
you're going to if optionally if you
would like to you can send a hint that
GL can recognize nicest or fastest to
tell the driver that you prefer either a
good the best looking possible
multisample or anti-aliasing or the
fastest possible for the number of
samples you picked that won't hurt even
if you're not it's an nvidia extension
but it won't hurt to call it on any card
it's not going to break your application
or reject it'll just ignore the setting
if the car does not support that
particular setting code for this will
get rid of the stuff that we've already
seen and really really simple here
sample buffers ARBs always gonna be one
samples are we're going to set the for
in this case i added the no recovery and
that basically means i don't want to
software back up as the software does
not support multi sample at this point
no recovery will tell you only to get
hardware renders and you can see more
about this on some one of the qas was
updated talking about multisample and
context selection GL and Abel
multisample ARB GL hinted multisample
filters in envy and nicest if I want to
use that and that's how to set up full
screen anti-aliasing so the final item
will talk about render to texture three
ways to do render to texture first a
surface texture you've had that in
Jaguar that was calling the a GL surface
texture got surface texture or the NS
create texture api's and you can use
them for surface texturing added for
Panther was P buffers it's a windows API
before prior to this also supported
across Linux it's a WGAL extension which
that extension take the meat out of it
and basically implement an API that
corresponds that we couldn't implement
exactly to the deals with things like
HTC's and a windows specific kind of
drawable code and formats well we've
done is make them make the set up a
little bit simpler but then make the
functionality the same it's more robust
on surface textures allows you to do
more things in the end what it allows
you to do it's create an accelerated
off-screen to do some rendering into and
then use that rendering as the source of
a texture it's supported an AGL cgl and
soon in NS GL the Panther that you have
does not have that support but by the
shipping time we should have the support
in for the NSEL version of the code to
use P buffers final message is super
buffers we're following closely with the
ARB working group on that working
directly with them and when the super
buffers extension is finalized well will
be shortly after that should be having
our implementation of that soapy buffers
we've talked about a little bit about it
generalize pixel buffers it can be a
target of rendering in this case you're
going to want use the commands like a GL
set P buffer or cgl set B buffer which
will basically say hey this is what I
rent want to render into think of that
as a set drawable call so basically have
an off-screen you call that and it's
going to your set drawable then if when
you want to render from that you're
going to use al text image p buffer or
cgl text image p buffers think of this
exactly as a texture 2d call to render
from the p buffer or you can even use
cube maps of p buffers or you can do a
cube map texturing and finally the setup
is going to be you're going to set it up
you create it you're going to draw to it
you're going to bind to it and then
you're a texture from it so code example
now I'm not going to go through all the
nuances here under understand that this
is things you've seen before with
creating p buffers there's an AGL create
p buffer call which is new so this and
then you have a set p buffer call which
is new but you notice these are very
similar to other AP out of the api's you
seeing stuff you use before you're going
to draw to it when you're finished
drawing to the P before you want to use
a GL flush to the flush it and then your
eye you set my current contacts to null
for safety to make sure i'm not drawing
to my people for my own
too so if i don't have a text your ID
created i'm actually going to generate a
texture i'm gonna bind stat texture and
then i'm going to use and i'm going to
set linear as a feds of parameter as a
filter perimeter here so i don't want to
have any mipmap speed offers do support
Mitt maps in this case I'm only example
II won't show an example without MIT
maps I'm going to texture from the P
buffer once I have that established and
I have that extra name establish I'm
going to bind to the T buffer directly
without a created using the text image
and then when I destroy it is going to
delete the texture destroy the pball for
destroy the contacts in the store the
pixel format like we've seen before
let's show a quick example of that
so what this example is was just a
square and then why did I took the
Stanford rabbit and I actually rendered
it to me I should use that actually
rendered the rabbit onto a pea buffer
and it's actually a flat you can see
from the top it's actually a flat
surface it's not so it's on each face of
the each face of the cube is rendered
the same same rabbit you can do a lot of
different things you could do any kind
of rendering you want to do as a source
here and then texture in any way
possible for example you could render to
mass and render a full la reflection map
rendered and then put it into the p
buffer go back to slides so I do have
one more quick thing to show you I think
we have we're a little bit into the Q&A
time but I'd rather show you this and
will we can hang around for questions if
people don't get enough answered at the
end I showed you that demo earlier we go
back to demo machine sorry I show you
the demo earlier of the how to create a
simple OpenGL sample well thinking about
it after Peter session we could take
that sample and fairly quickly extend it
to use the another method of getting
text on the screen and hike all the
images to with youth opengl which is the
cg on opengl and so we did was we took
that sample that we have before the way
i just created in a few minutes and we
added the code required to do that so
let me know to the bottom and show you a
code we added here so this little
section of code here basically is the
creative cg cgl contact you see a GL
context in addition to OpenGL view we're
going to create a color space there and
then we're going to use this a new call
see ggl context create which actually
creates a CG context based on that
opengl context we've created to draw cg
into me shoot back to the top here then
we add a lot a lot of code in this first
session but this is all CG code to draw
something more interesting than nothing
so all this is just cg drawing code
others I thought drawing one line to the
screen would be pretty boring so the kit
the key here is this CG draw routine
which it does the as the phils and the
throw
and those kind of things that's a key
routine at the very bottom let me scroll
it up so you all can see that it's a
classy G context flush and what this
does is actually flushes the drawing out
so when you when you actually draw the
OpenGL and flush the open shell contacts
into the swap their you actually get the
CG context state updated additionally
going back to the bottom things that we
add us we have with that one little
piece of code and we then we added we
flush our GL drawing and then we just
added the draw CG to the open children
routine this is a draw record king this
is exactly the same code no changes for
the code so i ended up i added the cg
drawing i added the sea to create and i
added to see the draw CG call to call
that CG drawing that was it and so what
I end up getting from that is save time
I already built this is the kind of the
Ovaltine sample with the spinning square
in the background you can see these are
all the shapes in the front we're all
drawn with CG it's a trench good doing
good transparency and good blending with
it's a pre premultiplied alpha on the
square and you can easily add CG
overlays or CG content to your OpenGL
views and to your open shield windows
just wanted to show you that show you
how easy it was to use those new
routines so back to the slide so again
we talked in the introduction but a
little bit about OpenGL we talked about
the interfaces we didn't talk about some
techniques everywhere everyone can use
in their apps and we talked about some
tips again I want to point out that
there is sample code out for almost
everything we showed here there's one QA
that i'll be posting later this week and
the p buffer sample will be posted
probably the very beginning of next week
or shortly thereafter it's complete it
just needs to be run through the be
posting process everything else is on
the web available for your use so you
can go look at it today the best place
to go to for more information though is
the developer.apple.com flash opengl
this links to sample code there's links
documentation that's a good central
repository for or a good another good
place for opengl in general is the
opengl org website and I'm going to
shoot through here there's some a
documentation I'll link to from it the q
and A's I referenced the tech note that
I reference all the samples that were
reference that are all all the samples
are on the web they're all
listed on the OpenGL website and then
I'm going to bring travis up to talk
about the road map and see we'll take
some questions thank you Joe so real
quick what I want to do is just pop
through the rest of the graphics imaging
track we have for you here at wwc and
folks from the OpenGL related session
you know next actually interestingly
enough in this hall immediately
following this presentation is a special
presentation that was not in your show
guides and that is the technology magic
a keynote and this is where we have an
engineer the lead engineer on the
keynote product our presentation package
it's going to come essentially talk
about talk shop about the application
and tell you what technologies they
adopted obstacles they overcame when
delivering the application and the
interesting point is that app is a heavy
user a heavy client of OpenGL technology
for a lot of its transition into the
effects then obviously we have image
capture update which you talk about our
scanning and digital camera support API
and tried the system so then we sort of
dive into the deep end of the pool with
OpenGL starting on Wednesday we have a
vertex programming with OpenGL a big
theme that we talked about in the
graphics imaging overview session was
programmability harnessing the GPU to do
interesting things to have a section on
vertex program ability and then also if
you notice on Thursday we have a session
on fragment programmability and these
are really key sessions if you want to
be at the sort of cutting edge of the
evolution of both 3d and 2d graphics
using the GPU we're also going to talk
about courts 2d and depth on Thursday as
well another big announcement that we
made in the graphs managing overview and
Jeff did the quick demo where we have
the ability to take our 2d drawing I API
courts 2d also known as cg by short it's
a whole different story and point it to
an open jail context and that was with
the Ovaltine example if Jeff showed you
at the end what about and then we have a
key session if you're developing any
OpenGL applications on Mac OS 10 you
want to cheat attend section 29 which is
OpenGL optimizations you're going to
learn just tons of information about how
to make OpenGL applications run as fast
as possible in the
platform and we're in a lot about our
enhanced OpenGL profiler application and
then I want to jump down into
cutting-edge OpenGL technique which is
on Friday and this is going to be a
great session that's going to we have
our hardware partners from ati who their
demo gods essentially going to come and
tell us how they do a lot of the you
know absolutely cutting edge effects
they do in their demo applications may
be very interesting for you guys to
learn from they're going to talk about
all sorts of different levels of
programmability vertex program a
building experiment programmability and
then obvious we have a feedback form one
friday so what we want to do is need to
contact either of us i can be contacted
on Travis at apple com and Jeff also
answers developer questions and he can
be found at chief stall at apple com