GPWiki.org
GPWiki.org
It is currently Fri May 24, 2013 3:56 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Tue Dec 07, 2010 6:30 am 
Hi guys :)
I just tried this tutorial: http://gpwiki.org/index.php/OpenGL:Tuto ... troduction
So, after some starting problems i got it running but all i see is a black screen. The render()-method is called, i checked that, but still no square...
Any hints for me?


Top
  
 
 Post subject:
PostPosted: Tue Dec 07, 2010 8:16 pm 
Cubic Contributor

Joined: Fri Apr 09, 2010 4:16 pm
Posts: 69
Location: wichita KS
Well, I have never used the graphics code you are using, (I just use paintComponent) but I might possibly be able to help if you post any and all error messages that occur when you run the program.

_________________
I code theirfor I am.
And more importently, theirfor my program am.
wait is that right... theirfor my code ams? no...theirfor i is... no... oh idk


Top
 Profile  
 
PostPosted: Mon Feb 07, 2011 5:43 am 
I'm having the exact same problem with the same tutorial. Here is all of my code.

Based on http://gpwiki.org/index.php/OpenGL:Tuto ... troduction

Imports Class and vars
Code:
import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import static org.lwjgl.opengl.GL11.*;

public class Game
{
    /*** Game title */
    public static final String GAME_TITLE = "My Game";

    /** Desired frame time */
    private static final int FRAMERATE = 60;

    /** Exit the game */
    private static boolean finished;

    /** Angle of rotating square */
    private static float angle;

...
...
}


The Main Function
Code:
    public static void main(String[] args)
    {
        boolean fullscreen = (args.length == 1 && args[0].equals("-fullscreen"));

        try
        {
            init(fullscreen);
            run();
        }
        catch (Exception e)
        {
            e.printStackTrace(System.err);
            Sys.alert(GAME_TITLE, "An error occured and the game will exit.");
        }
        finally
        {
            cleanup();
        }
        System.exit(0);
    }



The Init Function
Code:
    private static void init(boolean fullscreen) throws Exception
    {
        // Create a fullscreen window with 1:1 orthographic 2D projection (default)
        Display.setTitle(GAME_TITLE);
        Display.setFullscreen(fullscreen);

        // Enable vsync if we can (due to how OpenGL works, it cannot be guarenteed to always work)
        Display.setVSyncEnabled(true);

        // Create default display of 640x480
        Display.create();
        glViewport(0, 0, 800, 600);

    }


The Run Function
Code:
    private static void run()
    {
        while (!finished)
        {
            // Always call Window.update(), all the time - it does some behind the
            // scenes work, and also displays the rendered output
            Display.update();

            // Check for close requests
            if (Display.isCloseRequested())
            {
              finished = true;
            }

            // The window is in the foreground, so we should play the game
            else if (Display.isActive())
            {
                logic();
                render();
                Display.sync(FRAMERATE);
            }

            // The window is not in the foreground, so we can allow other stuff to run and
            // infrequently update
            else
            {
                try
                {
                    Thread.sleep(100);
                }
                catch (InterruptedException e)
                {
                }

                logic();

                // Only bother rendering if the window is visible or dirty
                if (Display.isVisible() || Display.isDirty())
                {
                    render();
                }
            }
        }
    }



The Render Function
Code:
    private static void render()
    {
        // clear the screen
        glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

        // center square according to screen size
        glClearColor(0f, 0f, 0.5f, 1.0f);
        glPushMatrix();
        glTranslatef(Display.getDisplayMode().getWidth() / 2, Display.getDisplayMode().getHeight() / 2, 0.0f);

        // rotate square according to angle
        glRotatef(angle, 0, 0, 1.0f);
        glBegin(GL_QUADS);
            glColor3f(1.0f, 0.0f, 0.0f);
            glVertex2i(-50, -50);
            glVertex2i(50, -50);
            glVertex2i(50, 50);
            glVertex2i(-50, 50);
        glEnd();

        glPopMatrix();
    }


Logic
Code:
    private static void logic()
    {
        // Example input handler: we'll check for the ESC key and finish the game instantly when it's pressed
        if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
        {
            finished = true;
        }

        // Rotate the square
        angle += 2.0f % 360;
    }


Cleanup
Code:
    private static void cleanup()
    {
        // Close the window
        Display.destroy();
    }


When I run all this I should get a rotating square in the center of my screen. Instead I get a blank blue screen.
I changed the background from black to blue to make sure the square wasn't the same color as the background. I adjusted the imports a bit from the tutorial trying to get it to work, but it didn't work when copied exactly from the tutorial either.

Any ideas?


Top
  
 
PostPosted: Mon Feb 07, 2011 9:46 pm 
Cubic Contributor

Joined: Fri Apr 09, 2010 4:16 pm
Posts: 69
Location: wichita KS
Sry, I don't really have anything. You might check if the background is being rendered over the foreground, but I can't really read that code. I have never used LWJHL, and the code for it doesn't look anything like the graphics I use. I use swing for graphics, and it has always worked fine for me.

_________________
I code theirfor I am.
And more importently, theirfor my program am.
wait is that right... theirfor my code ams? no...theirfor i is... no... oh idk


Top
 Profile  
 
PostPosted: Thu Feb 17, 2011 1:04 pm 
Bibliotherapist
User avatar

Joined: Wed Nov 03, 2004 1:28 pm
Posts: 6719
Location: Oxford, Englandshire
There's been an edit to the LWJGL wiki page that adds a projection matrix setup. That should fix the issues.

_________________
10 PRINT "Bad Monkey ";
20 GOTO 10


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group