iDevGames Forums
RenderSystem design - Printable Version

+- iDevGames Forums (
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: RenderSystem design (/thread-3128.html)

RenderSystem design - JeroMiya - Aug 3, 2007 04:13 PM

I'm attempting to make a very simple abstract RenderSystem class in Java. A RenderSystem basically draws simple 2D primitives, loads and manages textures/images, and so on. The goal is to be able to have an implementation using Java2D if I want to write an applet, and eventually JOGL as I add features like alpha blending, transformations, shaders, etc..

Unfortunately, I'm having difficulty designing such a thing. The problem is that a lot of things are tied to the actual implementation. For example, to use Java2D, it must be associated with a Frame. JOGL needs, I think, a special GLContext object which is also associated with a frame of some sort. So in essence the RenderSystem is tied to the window or frame object I'm using, so it must also handle window/frame creation, event handling, etc..

Does anyone have any suggestions for this?

Here is the current version of the RenderSystem class:
* Created on July 19, 2007, 5:54 PM
* To change this template, choose Tools | Template Manager
* and open the template in the editor.

package tama;
import tama.Color;
import tama.Square;

* @author Jeremy Bell
abstract public class RenderSystem
    public class Texture
    private int mID = -1;
    public Texture() {
    public Texture(int id) {
        mID = id;
    public void setID(int id) {
        mID = id;
    public int getID() {
        return mID;
    protected Color mCurColor = null;
    protected Texture mCurTexture = null;
    protected Color mClearColor = new Color(1.0, 1.0, 1.0, 1.0);
    public RenderSystem() {
    // ==============================================
    // Action Methods
    abstract public void startFrame();
    abstract public void endFrame();
    abstract public void clear();
    abstract public void drawSquare(tama.Square square);
    abstract public RenderSystem.Texture loadTexture(String fileName);
    // ==============================================
    // Access methods
    void setClearColor(tama.Color col) {
    mClearColor = col;
    tama.Color getClearColor(tama.Color col) {
    return mClearColor;
    void setCurColor(tama.Color col) {
    mCurColor = col;
    tama.Color getCurColor() {
    return mCurColor;
    void setCurTexture(RenderSystem.Texture tex) {
    mCurTexture = tex;
    RenderSystem.Texture getCurTexture() {
    return mCurTexture;


RenderSystem design - AndyKorth - Aug 3, 2007 06:46 PM

Two brief points. I don't think you'll want to be mixing Java2D drawing with JOGL drawing. In fact, I doubt it's really possible in a clean manner at all.

The creation of a tama.Color confuses me. Have you looked at java.awt.Color?

Finally, I'd seperate out some of this logic, or you'll find that a single RenderSystem class will become a huge mess. Make a gameWindow that extends JFrame. Inside that GameWindow, include a GamePanel, (or GameViewport, GraphicsPanel), whatever you want to call it. Make this panel extend JPanel and override the paint method. (find a tutorial regarding drawing stuff here, or find some example code)

When you switch to JOGL, you'll probably want to make a JOGLPanel or something to draw to. (I don't have much experience with JOGL)

I notice that RenderSystem is an abstract class. What will it's concrete subclasses be exactly?

Finally, don't get discouraged, it took me many changes to get a rendering system I was moderately happy with... and it's still changing. You'll learn a lot in the process!

RenderSystem design - JeroMiya - Aug 4, 2007 07:37 PM

I'm not actually mixing the two. Here's the situation. This is a game I'm writing for my fiancee'. She has a lot of memories as a kid with Tamagotchi so I'm writing her a little Tamagotchi game. It's written in Java and I want it to run as both an unsigned applet, so she can play it at school on the university computers, and also as a standalone application at home. In the future I'm also going to be looking into porting it to the Palm so she can play it anywhere.

Although JOGL can be used with unsigned applets but with some difficulty. I believe you have to run an installer, which she won't be able to run. So I just want to use the built-in Java2D.

For the standalone application, I'll probably still use Java2D since that's all I really need at this point, but maybe in the future I might want to use JOGL for other things, like animations.

And I have no idea what I'd have to do for the palm. I'm assuming it has at least some Java2D functionality, but loading images might be a bit different considering the palm's file system.

So yeah, that's the reasoning behind using an abstract RenderSystem, so I can port the game to all these options, without recoding all the drawing logic in the game.

Hope that clarifies things,