0

I am using LWJGL to create a game in java. However it's not rendering, I have it setup to simply render 6 planes, each facing towards the inside to surround the camera in a box, it's very simple code, and I have working code that is almost exact, just messier.

public void start()
{
    try
    {
        Display.create();
        Display.setVSyncEnabled(true);
    }
    catch(LWJGLException e)
    {
        e.printStackTrace();
        System.exit(0);
    }
    fps = new FPSCameraControl(64F, 20F, 64F);

    world = new World("Test", 0, new Vector2f(1024,1024));
    world.generate(128, 128);

    GL11.glEnable(GL11.GL_CULL_FACE);

    GL11.glEnable(GL11.GL_ALPHA);
    GL11.glEnable(GL11.GL_BLEND);

    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glShadeModel(GL11.GL_SMOOTH);

    GL11.glEnable(GL11.GL_DEPTH_TEST);

    GL11.glDepthFunc(GL11.GL_LEQUAL);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();      

    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); 

    Settings.paused = false;
    Settings.paused_state = false;

    disableOrthoView();

    start_game_loop();
}
private static void start_game_loop()
{
    enableOrthoView();

    while(Settings.active)
    {
        GL11.glColor3f(1F, 1F, 1F);

        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glLoadIdentity();

        //Handle Pause Control
        if(Keyboard.isKeyDown(Keyboard.KEY_P))
        {
            if(!Settings.paused_state)
            {
                Settings.paused = (!Settings.paused);
                Settings.paused_state = true;
            }
        }
        else
        {
            Settings.paused_state = false;
        }
        if(!Settings.paused && Display.isActive())
        {
            fps.onUpdate();
        }
        fps.lookThrough();
        if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
        {
            Settings.active = false;
        }

        GL11.glPushMatrix();

        world.render();

        GL11.glColor3f(1F, 1F, 1F);

        GL11.glPopMatrix();

        GL11.glColor3f(1F, 1F, 1F);

        Display.update();
    }
    Display.destroy();
}
public static void enableOrthoView()
{ 
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glPushMatrix();
    GL11.glLoadIdentity();
    GL11.glOrtho( 0, 800 , 600 , 0, -1, 1 );
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPushMatrix();
    GL11.glLoadIdentity();
}
/**
 * Disables the orthographic view.
 */
public static void disableOrthoView()
{
    GL11.glMatrixMode(GL11.GL_PROJECTION );
    GL11.glPopMatrix();
    GL11.glMatrixMode(GL11.GL_MODELVIEW );
    GL11.glPopMatrix();
}

The world code is as follows:

public class World
{
    HashMap<Integer, HashMap<Integer, Object>> tiles = new HashMap<Integer, HashMap<Integer, Object>>();

    private int mx=0;
    private int my=0;

    public static int height = 0;

    private String name;

    public World(String _name, int _height, Vector2f size)
    {
        name = _name;

        height = _height;

        generate((int)size.x, (int)size.y);
    }
    public void generate(int _x, int _y)
    {
        for(int x = 0;x<_x;x++)
        {
            tiles.put(x, new HashMap<Integer, Object>());
            for(int y = 0;y<_y;y++)
            {
                tiles.get(x).put(y, null);
            }
        }
    }
    public void render()
    {
        GL11.glBegin(GL11.GL_QUADS);

        GL11.glColor3f(1F, 1F, 1F);

        GL11.glNormal3f(0.0F, 1.0F, 0.0F);

        GL11.glVertex3f(0F, 1F, 0F);
        GL11.glVertex3f(0F, 1F, my);
        GL11.glVertex3f(mx, 1F, my);
        GL11.glVertex3f(mx, 1F, 0F);

        GL11.glNormal3f(1.0F, 0.0F, 0.0F);

        GL11.glVertex3f(0F, 1F, 0F);
        GL11.glVertex3f(0F, 100F, 0F);
        GL11.glVertex3f(0F, 100F, my);
        GL11.glVertex3f(0F, 1F, my);

        GL11.glNormal3f(-1.0F, 0.0F, 0.0F);

        GL11.glVertex3f(mx, 1F, 0F);
        GL11.glVertex3f(mx, 100F, 0F);
        GL11.glVertex3f(mx, 100F, my);
        GL11.glVertex3f(mx, 1F, my);

        GL11.glNormal3f(0.0F, 0.0F, -1.0F);

        GL11.glVertex3f(0F, 1F, my);
        GL11.glVertex3f(0F, 100F, my);
        GL11.glVertex3f(mx, 100F, my);
        GL11.glVertex3f(mx, 1F, my);

        GL11.glNormal3f(0.0F, 0.0F, 1.0F);

        GL11.glVertex3f(0F, 1F, 0F);
        GL11.glVertex3f(0F, 100F, 0F);
        GL11.glVertex3f(mx, 100F, 0F);
        GL11.glVertex3f(mx, 1F, 0F);

        GL11.glNormal3f(0.0F, -1.0F, 0.0F);

        GL11.glVertex3f(0F, 100F, 0F);
        GL11.glVertex3f(0F, 100F, my);
        GL11.glVertex3f(mx, 100F, my);
        GL11.glVertex3f(mx, 100F, 0F);
        //COMMENTED OUT - UNIMPLEMENTED - REMOVED FOR TESTING
        /*for(int x = 0;x<mx;x++)
        {
            if(tiles.containsKey(x))
            {
                for(int y = 0;y<my;y++)
                {
                    if(tiles.get(x).containsKey(y))
                    {
                        ((Item)tiles.get(x).get(y)).render(x, y);
                    }
                }
            }
        }*/
        GL11.glEnd();
    }
    public void placeEntityAt(int x, int y, Object entity)
    {
        tiles.get(x).put(y, entity);
    }
    public void save() throws IOException
    {
        PrintWriter file = new PrintWriter(new File("..\\data\\worlds\\"+name+".rnw"));

        for(int x = 0;x<mx;x++)
        {
            if(tiles.containsKey(x))
            {
                for(int y = 0;y<my;y++)
                {
                    if(tiles.get(x).containsKey(y))
                    {
                        Object o = tiles.get(x).get(y);

                        String line = "-t ";

                        line += WorldObjectType.getObjectTypeID(o)+"[";

                        line += ((Item)o).getSaveParams()+"]{"+x+"."+y+"}";

                        file.println(line);
                    }
                }
            }
        }
        file.println("-m '"+name+"' "+mx+"|"+my);
    }
    public void load()
    {

    }
}

The FPSCameraControl is very simple just uses the mouse location to add the yaw and pitch and then uses GL11.glRotatef, with the correct axises, cause that class is just copied from an ealier test wich worked completely.

I have been having this issue for 3 days so far, been constantly checking my code, if anyone can spot where there's a problem please reply soon.

D3_JMultiply
  • 1,022
  • 2
  • 12
  • 22
  • It would be helpful if you could provide two complete source files with main methods for us to run. Preferably without methods like `save()` which aren't needed for rendering. – Daniel Lubarov Feb 25 '12 at 05:52
  • Are you getting an error or is the result just a black screen? A suggestion would be to use JMonkeyengine if you are developing a game: http://jmonkeyengine.com/ – Emil L Feb 25 '12 at 06:57
  • unfortunatly, in order to supply the two files to run, I would need to include about 14 other files that are used. I mainly wanted someone to look over the script and say if they saw any notable errors in the rendering process, like something should be in a different order. For the project I am not allowed to use JMonkeyEngine, however I know it would help, but I'm only supposed to use OpenGL and OpenAL or any binding for them, I chose Java because I'm more familliar with it. – D3_JMultiply Feb 26 '12 at 00:26
  • And PS, I am not getting any errors, and I know the screen is black for a reason, it's not a black screen as in nothing even hapening, I know that it's registereing everything because I can change the sky color, just my floor, walls, ceiling don't work. – D3_JMultiply Feb 26 '12 at 00:27

0 Answers0