[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] getting setup to use PyOpenGL for 2D



On Monday 28 November 2005 18:53, D. Gyimesi fired a shotgun at the keyboard 
and the following appeared:
> > 	It's really not bad if you write some basic framework for handling your
> > 2D stuff. I like to treat it sorta like Pygame's sprite module....I'll
> > have a generic class that loads a texture, contains a display list with
> > the quad that makes up the object, has X and Y attributes, maybe a zoom
> > attribute, etc. It will have something like an update function (or even a
> > seperate draw function) that will contain the basic OpenGL rendering
> > code. From there all I have to do is call one or two functions of that
> > object every cycle. Another tip: for 2D, orthogonal matrices are your
> > friend. :)
>
> Same thoughts here. :) But I've some fear about onscreen coordinates. In
> SDL pixel coords are very comfortable. I know OpenGL know this feature
> too, but you must set up glViewport() and glOrtho() for this to keep
> your sprites size correct.
>
> Orthogonal matrices. Yuck! I had linear algebra two years ago (in the
> first semester), but I don't like it much despite of that is heavily
> used in computer graphics.

	Eh? Nothing to fear here. All the ortho matrix does is, well, makes 
everything ortho. :) You only need to worry about two axis....you just adjust 
coords of the third axis as necessary to put visible objects on top of 
background objects etc (actually, if you were real careful about the order in 
which you draw objects, and disabled depth testing, you wouldn't even need to 
worry about this.......and this would save on performance too....hmmm I'll 
probably go this route myself).
	In my latest game, I just have my world set up to use pixel units...ie, one 
OpenGL unit corresponds to one pixel on the screen (at 1024x768). Of course, 
at other resolutions this will no longer be true, but that's fine because 
once we've set up our coord system and figured out limits for scrolling, 
active area to check for collisions, that sort of thing, we don't really need 
to worry about this anymore (and at other resolutions, OpenGL scales 
everything for us). In fact if you're not tracking the mouse, you really 
don't have much reason to match up units to res at all, other than it makes 
it easier to keep aspect ratio correct (no conversion from pixels to OpenGL 
units necessary). It's just a convenient way of thinking of things (one more 
thing to simplify).

	-Matt Bailey