Latest Posts

Changes in ImplementOpenGl

Revision Differences of Revision 3

# Status ¶

## Current State ¶
- Experimental: I pushed a first Version where opengl rendering works ¶

## Working on ¶
- separating OpenGL code and SDL software rendering code ¶
- throwing out the font code at least from the GL Path ¶

## To be done ¶
- just to much ¶

# Howto test it: ¶
- get the branch ¶
- create a build directory ¶
- invoke cmake /path/to/source -DCMAKE_CXX_FLAGS="-DUSE_OPENGL -DHAS_OPENGL" -DCMAKE_EXE_LINKER_FLAGS=-lGL ¶
- run make us usual ¶

Do not report bugs in the current state. At the moment it's just an experiment. ¶

## Implementation ¶
currently it is somehow mixed with the SDL software rendering code. It is done by choosing the OpenGL or the Software path based on a global variable (g_opengl). Most of the changes are in the classes Surface, Graphic and RenderTarget. The initialisation is done in Graphic. RenderTarget does some small things (Drawing lines) and renders the Game. Surface does blitting transform SDL_Surface to OpenGL textures. Pictures are read as without OpenGL as class Surface. If they are blitted using opengl, the SDL_Surface is transformed in an OpenGL Texture. The generated Texture is cached in the Surface. So the transformation occurs only once for every picture. The code works but is quite ugly. This is what is currently in the branch. ¶

That is what I do local: ¶

I made the class Surface virtual and disallow accessing the SDL_Surface directly. This class provides function to blit and draw primitives. This class is inherited by SurfaceOpenGL and SurfaceSDL. These implement the rendering code. This broke the code (of course). The worst thing is the font code. It relies on using the SDL_Surface. RenderTarget and Graphic needs some changes to reflect the changes to Surface. As soon as the code works with these changes again I will push to the branch.
OpenGL and SDL is separated now. Class Surface is virtual and code compiles partly again ¶

- Get everything compile and link again ¶
- get image loading and game rendering working ¶

## To be done ¶
- reimplement image Loading ¶
- reimplement font handling ¶
- reimplement drawing the game ¶
- reimplement drawing the minimap ¶
- merge with trunk and modify cmake ¶

(gameview and minimap will get their own class soon) ¶

# Howto test it: ¶
This branch is outdated. It's a proof of concept only. ¶

- get the branch ¶
- create a build directory ¶
- invoke cmake /path/to/source -DCMAKE_CXX_FLAGS="-DUSE_OPENGL -DHAS_OPENGL" -DCMAKE_EXE_LINKER_FLAGS=-lGL ¶
- run make us usual ¶

Do not report bugs in the current state. At the moment it's just an experiment. ¶

## Implementation ¶
The current code relies on SDL software rendering a lot. The class Surface is used for image handling and rendering. This class exposes some SDL internals to widelands and these are use in some places. There is a class Graphic which is the main interface between widelands and the graphic system. Currently there is some game related code in the Surface, Graphic and Rendertarget classes. ¶

The first step was making Surface a Virtual base class which does not expose any SDL internal to the rest of widelands. There are two classes which inherit from Surface and implement actual renderers. They are called SurfacedSDL and SurfaceOpenGL. Everything from the game should use only the virtual class Surface and the global object g_gr of class Graphic. Graphic will have methods to create Surfaces and to Load Images to Surfaces. Rendering the game and the minimap code is currently scattered somehow over some classes and source files. I will move this code to an own class. ¶

Everything related to rendering now goes to graphic/render subdirectory. Everything else except some classes from graphic/ subdirectory (Graphic and perhaps font_handler) should not know anything about these different renderers.


# Links ¶
[Branch on launchpad](https://code.launchpad.net/~timo-wingender/widelands/graphicsystem-opengl)