PDA

View Full Version : [Unit] Sour



Super Vegeta
08-10-2012, 11:05 AM
Sour stands for SDL-OpenGL Unsophisticated Rendering and is a simple unit for performing some basic 2D OpenGL drawing with SDL. The interface was written to mimic the software rendering API of SDL as much as possible, to make sure anyone who has ever used SDL will be able to quickly switch to using Sour, without any loss of productivity and development speed.

Sour was originally developed as part of one of my game projects. Since the project did not require any sophisticated graphics and I didn't really want to learn OpenGL thoroughly from the beginning, I decided to make myself a simple rendering unit that could easily replace SDL software drawing.

Sample screenshot, presenting FillRect, TexRect, DrawImage, DrawImgRot and PrintText:
http://svgames.pl/trash/sour0.png
Download: click (http://svgames.pl/file/sour)
The unit comes with a full HTML documentation.

Since I'm an OpenGL newbie myself and parts of the code were taken from google, it would be very appreciated if someone took a look at the code (mainly initialization and setup routines) and pointed out what am I doing wrong and what can be improved.

User137
08-10-2012, 12:38 PM
Procedure DrawImage(...);
begin
glENABLE(GL_Texture_2D);
glBindTexture(GL_Texture_2D, Tex^);
glBegin(GL_Quads);
...
glEnd();
glDISABLE(GL_Texture_2D)
end;
You have this as a base for every drawing operation. Especially the glBindTexture() is a heavy operation. Consider when you would need to draw 10000 particles with same texture, it would call that pointlessly 9999 times per frame. It's possible to store last used texture-index and skip bind if its unchanged, but it comes with problems if some other operation binds without letting your engine know. I went with SetTex() function myself, but that might not go well with SDL-style programming.

Other thing i found when quickly skimming through, was:

Procedure SetGLAttributes(R,G,B,Double:LongWord);
Is that even possible, i could do this?

var double: double;
Usually recommended to avoid using reserved names in variables and constants.

But overall seemed good work of course ;)

Super Vegeta
11-10-2012, 12:46 AM
Okay, so having some free time this evening, I gave this thing some extra work and bumped the version to 1.1.

Thanks to User137, I made the unit remember if texturing is enabled and the boundtex number - and it turned out the thing works way faster now. Furthermore, I implemented a proper initialisation procedure, making starting the unit, at least in my opinion, as easy as it can get. Also, I added some extra routines allowing to change the settings and (duh) free resources.