Re: openGL to emulate QuickDraw (i.e. 2D projection)
- From: "j" <j@xxxxxxxxxxxx>
- Date: Tue, 16 Aug 2005 04:40:21 GMT
Dont mind Funghi, he's a bit well, weird.
Anyway, your question as to how to use opengl for
2d drawing; it's quite a bit different than quickdraw
i presume, not knowing very much of qd myself but
having 'seen' it. It is very well possible however
and it gives you an awful lot of control over your
textures etc. Anyway, just to set up a 'working canvas'
the idea is that you have 4 'environments' so to speak;
( just talking 2d now... )
1 is the actual window you're drawing to,
2 is the area of the window you use
3 is a camera looking at the canvas top-down
4 is the canvas itself.
Now, all 4 can be resized and positioned at will,
and all three have their particular set of commands.
1. the commands for the window are _not part of OpenGL_
because ogl is only concerned with actual drawing and
transforming, not with opening windows. However there is
this library called glut ( latest version 3.7 I believe )
which is quite old by now, but that means also it's quite stable.
Have a look at it f.i. at http://www.lighthouse3d.com/opengl/glut/
2. the area of the window you can use is called the viewport,
and the most important function to set it is, appropriately enough:
glViewport( x, y, w, h ). with x,y being the lower-left corner
of the rectangular area relative to the lower-left corner of the window.
( in OpenGL everything is always relative to the lower-left corner )
and w and h being the width and height of the area. Then there is
also a function called glScissor which allows you to use only a part
of the viewport, but I wont go into that now.
3. The 'camera' is nothing but a 4x4 transformation-matrix ( if you
dont know what that is, just think of it as an old-fashioned
pinhole camera. the size and distance of the backside of the box
relative to the center of the frontside determines the size of the
picture you get. Of course, you could also shear and skew
the box to distort the picture and you can actually do exactly this
in openGL but again, I wont go into that detail.)
This 'box' is called the GL_PROJECTION and
is manipulated by glMatrixMode and its partner functions
like glTranslate, glScale, etc. glLoadIdentity gives you
a standard sized camera. you can use the utility functions like
glOrtho or gluPerspective to specify different sized boxes.
The picture on the back of this camera is what you'll see
in your viewport.
4. The canvas works pretty much like the camera in that
you can skew and shear it, scale, etc. with actually the
same commands, just _after_ you've called glMatrixMode
with the argument GL_MODELVIEW.
so, for an example, we draw a point at ( 0,0 ) with
//-------------------------------------
glViewport( 0,0, windowwidth, windowheight );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( -1, 1, -1, 1, -1, 1 ); // ( a square box-camera with size 2 )
glMatrixMode( GL_MODELVIEW );
glLoadIdentity(); // we dont do anything to the canvas, just let it be flat
and square
glColor3f( 1,0,0 );
glPointSize( 10.0 );
glBegin( GL_POINTS );
glvertex2f( 0,0 );
glEnd();
//--------------------------------------------
and drawing a circle of points:
//-------------------------------------
glViewport( 0,0, windowwidth, windowheight );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( -1, 1, -1, 1, -1, 1 ); // ( a square box-camera with size 2 )
glMatrixMode( GL_MODELVIEW );
glLoadIdentity(); // we dont do anything to the canvas, just let it be flat
and square
for( i=0; i<36; i++ ){
glRotatef( 10, 0, 0, 1 ); // rotate the canvas 36 times 10 degrees
glColor3f( 1,0,0 );
glPointSize( 10.0 );
glBegin( GL_POINTS );
glvertex2f( 0,0 );
glEnd();
}
//--------------------------------------------
and that's it. Then have a go with glbegin( GL_LINES ) etc,
and experiment a bit with resizing the camera, canvas, etc.
( I always find it very useful when experimenting to couple the
parameters like scaling of the canvas to some value you can manipulate
on runtime, fi with your mouse and get a nice feel of what's happening )
Now, Ive tried to explain it in terms of traditional drawing-tools
which may be unconventional and even in some respects misleading
( as, Im sure, Fungus will not fail to point out ). I do believe that it's
a useful metaphore to get started however and as you progress,
you'll find out that there are some other ways of looking at it
( as, Im sure, Fungus will not fail to point out )
Enjoy, and dont let people bring you down by leading
you into a dark forest saying its very cool once you know it.
feel free to respond to my emailaddress,
regards,
Jonathan
.
- References:
- openGL to emulate QuickDraw (i.e. 2D projection)
- From: testie
- Re: openGL to emulate QuickDraw (i.e. 2D projection)
- From: fungus
- Re: openGL to emulate QuickDraw (i.e. 2D projection)
- From: testie
- Re: openGL to emulate QuickDraw (i.e. 2D projection)
- From: fungus
- Re: openGL to emulate QuickDraw (i.e. 2D projection)
- From: testie
- openGL to emulate QuickDraw (i.e. 2D projection)
- Prev by Date: Re: Using the arrow keys.
- Next by Date: Re: Icons for the programs
- Previous by thread: Re: openGL to emulate QuickDraw (i.e. 2D projection)
- Next by thread: Re: openGL to emulate QuickDraw (i.e. 2D projection)
- Index(es):
Relevant Pages
|