GSoC project: Sprite engine overhaul - Weekly A&O report #3

Hi everyone!
Time for this weeks A&O report.

As indicated by last weeks objectives, I've started reducing the Fixed Function Pipeline (FFP) code,
which became obsolete with GL2 and finally deprecated with GL3/GLES2.

In particular I refactored pretty much all of the matrix related code.
So for me it was just doing some applied linear algebra that week.

OpenGL1 had a so called Matrix stack functioning like this:

glPushMatrix:
Backs up the current matrix.
Most GL implementations don't provide pusing more than 16 times, however Hedgewars required only one time.

glPopMatrix:
Restores the most recently pushed matrix.

glLoadIdentity:
Sets the current matrix to identity (1)

glScale, glTranslate, glRotate, glOrtho2d, (gl utility funcs gluPerspective gluOrtho):
Multiply the current matrix with specific matrices thus chaining the mapping.

These functions allowed for easy chaining of transformations like:
glRotate(), glTranslate(), glScale() would first rotate the object around its center
then move it along the rotated coordinate system and then scale the object.

As already stated this functionality became completley stripped at some point.
So I either had to emulate existing functionality with an own matrix stack and replacement versions of all the above functions, or I could explicitly calculate matrices
as needed.
The later option was quite a nice way to go, as Hedgewars first of all just uses 2d transforms
and futhermore all of them were composed like "translate rotate translate".

Thus replacing the reoccuring pattern of:
glPushMatrix() glTranslate(x, y, 0) glRotate(angle, 0, 0, 1); glTranslate(s, t, 0); glPopMatrix();

with:
m = calculate(x, y, angle, s, t); glLoadMatrix(m);

was a quite straight way to go, as opposed to use full blown matrix multiplications.

To keep the impact of the changeset low I decided to not have some god-function as calculate() above,
but provided utility funcs that semantically mimic the initial variant, operating on a global variable.

Thus the final code now looks like:
SetOffset(x, y); SetRotation(angle); AddOffset(s, t); UpdateModelview; ResetModelview;

Optimally the Reset wouldnt be required, but I couldnt get it changed thus far yet, due to how the rendering funcs are used.

By next week you might already expect an initial GL2 version.
I'll probably go in two steps here though.
The initial version would use a plain compatibility shader using ftransform() and fixed function pipeline as well as the ffp passed glColor.
After this s accomplished I'll replace both, the tinting (which already has a shared update point with the tint() function) and the matrix
related code, which became one with UpdateModelview, with uniforms.

Once this is done we should have GL3 and ES2 compatibility for most parts.

Hmm... will there still be an option to play it with OpenGL 1.3 compatibility? We play this game quite a bit at my Sixth Form* (found it through PortableApps.com) but we've found out with the game Xonotic (also open source) that the computers don't support OpenGL 2.0!
Will it still be playable there?

I'm not a programmer, please don't just paste any code!

*School in England for 16-18 year olds.

WolfgangSt has stated as a goal that he intends to try and preserve GLES11 compatibility.
Sooo, yes I guess.

For the moment I'm keeping everything backwards compatible. However if for example, at some point shaders are used to realize special effects for game content, these effects would be GL2+ exclusive.

I think nemo's right that you start as a goal.

User login

Copyright © 2004-2024 Hedgewars Project. All rights reserved. [ contact ]