day #4, a camera part two(this got really long -- it really is a diary entry! Read on if you like long rambling diary entries.)
It happened, I got inspired to learn more OpenGL to handle the scrolling about the level, and spent all of the night on it. Getting it going was fast, but I'm still dealing with some problems. One of the reasons I went from Pygame to pyglet was to learn OpenGL in fact, but up to now I've only used the most basic functions, so this process has been really fun! Some of this stuff is like magic. At the same time it seems like everyone does their GL a little differently so to speak, so it's difficult to get a straight answer from any of the billions of forum posts and tutorials out there to fix a problem. Luckily there are billions of places to look, so with a little digging things get clearer.
The problems seem to be that the sprites are not being drawn to the 'right' place on the viewport. It's a little hard to explain (as I'm not really sure what's going on ;) ). I've set the view to follow the player sprite, and as I track the player.x variable for example to the left in the debug window, it does collide where it should on the x axis and stop moving. But in the viewport the object the player collides with is still a little farther to the left than where it should be.
A second problem is that I can't figure out how to center the view on the player sprite; it's always off to the side a bit. There must be somewhere I can set a point to be half the window width and height, so I just have to figure that out. For example, every on_draw() I call gluLookAt like this:
self.x, self.y, +1.0,
self.x, self.y, -1.0,
sin(self.angle), cos(self.angle), 0.0)
This is from tartley's excellent slideshow and demo code. Self.x and self.y eventually converge on the player's position, so when the player moves the view 'floats' following the sprite. Basically then gluLookAt's eye point and reference point is the player position. However I haven't successfully added the 'center' of the screen to gluLookAt...maybe this isn't the function to define the center?
A third problem is that one of the sprites (strangely just the sprite that is the ground) sometimes shows a flickering black line at its top border (in the field of the screen where you can see it basically, as the sides and bottom are the window border). This problem cropped up only when I started using OpenGL for the scrolling (it wasn't a problem when I was scrolling before with a homemade pair of offset variables applied to the world coordinates).
I feel pretty good that I can take care of these issues, and tomorrow night is the first night I have a full uninterrupted stretch to work, so I'm hoping to make some progress.