Re: openGL to emulate QuickDraw (i.e. 2D projection)




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











.



Relevant Pages

  • Re: Noob alert: trouble resizing canvas when app window is manually resized
    ... the ideal result would be the canvas (and ... its contents) is redrawn to fill the new size of window, ... want to redraw - create and pack it once at startup, ... global .c xpixels ypixels resizes ...
    (comp.lang.tcl)
  • Re: Troubles with setting OE6 as a default email client in XP
    ... > and I can't add it because I dont have administrator's rights. ... See if you can check on your settings from a command window. ... > wanted to say is that I can't make my default client neither OE nor OL. ... >> I have problem with setting OE6 as a default email client. ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Re: UI subsystem interface design
    ... The application constructs its UI by composing the primitive drawing objects and then giving those objects as data to the subsystem, which will be responsible for doing the drawing based upon the data it is given. ... Each window is a rectangle and contains coordinates for its position represented as floating-point numbers between 0 and 1. ... There has to be a mapping of the message data packets in the subsystem interface and you will need some way to ensure that mapping, but I don't see that being dedicated identity objects. ...
    (comp.object)
  • After i go to this Web Sit i have many virus he instal he want without permission ! its very Dangero
    ... And i see he install me a program (i see in Add/uninstall Programs) the ... PLEASE help me:((i format all my computer and install again and i have the ... open a porno popup AND another window but this time He Ask Me if i accept a ... check my system because i dont undstand why.. ...
    (microsoft.public.scripting.virus.discussion)
  • After i go to this Web Sit i have many virus he instal he want without permission ! its very Dangero
    ... And i see he install me a program (i see in Add/uninstall Programs) the ... PLEASE help me:((i format all my computer and install again and i have the ... open a porno popup AND another window but this time He Ask Me if i accept a ... check my system because i dont undstand why.. ...
    (microsoft.public.security.virus)