My First Lwjgl Experiment does'nt work °.° ! Tips?

here it is, first i had some trouble to work with lwjgl but now it work correctly … hm now it statet to read some tutorialcode stuff and try’d what you see here, it work great but i dont see this …


              GL11.glBegin(GL11.GL_TRIANGLES);                              // Drawing Using Triangles
                    GL11.glColor3f(1.0f,1.0f,1.0f);                              // Set The Color To White
                    
                    GL11.glVertex3f( 0.0f, 1.0f, 0.0f);                        // Top
                    GL11.glVertex3f(-1.0f,-1.0f, 0.0f);                        // Bottom Left
                    GL11.glVertex3f( 1.0f,-1.0f, 0.0f);                        // Bottom Right
                GL11.glEnd();      

… whats wrong ?

Thank you all,

davidb :wink:




//-Djava.library.path=C:\Daten\Programme\L\lwjgl-win32-0.94-2\lwjgl-win32-0.94
public class Game {

        private static final String GAME_TITLE = "Basic Game Framework";
        private static final int    FRAMERATE  = 60;

        private static boolean gameRunning;
        //private static enum       gameStates {INIT, RUNNING, EXIT};
        //private static gameStates gameState;

        /** Settings for the desired display/window size */
        private int displayWidth  = 800;
        private int displayHeight = 600;
        private int displayBPP    = 16;

        /** Should the game run in fullscreen? */
        private static boolean fullscreen = false;

        /**
         * Initializes the game and sets it running by entering the main game loop.
         * After the main loop is broken from within it cleans everything up.
         */
        public Game()
        {

                /**
                 * Initialize the game
                 *
                 * < 1.5: Delete the line "gameState = gameStates.INIT;"
                 */
                gameRunning =false;
                initDisplay();
                initGL();
                initGame();

                /**
                 * Start the game
                 *
                 * < 1.5: Delete the line "gameState = gameStates.RUNNING;" and replace
                 *        it with "gameRunning = true;"
                 */
                gameRunning=true;
                gameLoop();

                /** Cleanup */
                Display.destroy();

        }

        /**
         * The entry point for the game. Creates an instance of this class which
         * will handle everything else.
         *
         * @param args The commandline arguments that are passed to the game
         */
        public static void main(String[] args)
        {
                new Game();
        }

        /**
         * Initialize the display. Tries to set the desired display mode as well as
         * some additional parameters and creates a window.
         */
        private void initDisplay()
        {

                /**
                 * Try to set the desired display mode, exit the game if it can't be set
                 */
                try {
                        DisplayMode modes[]   = Display.getAvailableDisplayModes();
                        boolean            modeFound = false;

                        /**
                         * < 1.5: The following enhanced for-loop doesn't work with Java
                         *        versions prior to 1.5. If you're using an older version
                         *        just replace the whole for-loop with the following:
                        */
                                for (int i = 0; i < modes.length; i++) {
                                    if (modes[i].getWidth() == displayWidth &&
                                        modes[i].getHeight() == displayHeight &&
                                        modes[i].getBitsPerPixel() == displayBPP) {
                                        modeFound = true;
                                        Display.setDisplayMode(modes[i]);
                                        break;
                                    }
                                }

                        /*
                        for (DisplayMode currentMode : modes) {
                                if (currentMode.getWidth() == displayWidth &&
                                    currentMode.getHeight() == displayHeight &&
                                    currentMode.getBitsPerPixel() == displayBPP) {
                                        modeFound = true;
                                        Display.setDisplayMode(currentMode);
                                        break;
                                }
                        }
                        */
                        if (!modeFound) throw new Exception();
                } catch (Exception e) {
                        e.printStackTrace(System.err);
                        Sys.alert(GAME_TITLE + "Error", "Unable to set desired display " +
                                "mode ("+displayWidth+"x"+displayHeight+"x"+displayBPP+").");
                        System.exit(0);
                }

                /**
                 * Set some parameters and create the display, exit the game on error
                 */
                try {
                        Display.setTitle(GAME_TITLE);
                        Display.setFullscreen(fullscreen);
                    Display.setVSyncEnabled(true);
                        Display.create();
                } catch (Exception e) {
                        e.printStackTrace(System.err);
                        Sys.alert(GAME_TITLE + " - Error", "Unable to initialize display.");
                        System.exit(0);
                }

        }

        /**
         * Initialize the OpenGL context.
         */
        private void initGL()
        {

        GL11.glShadeModel(GL11.GL_SMOOTH);
        GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        GL11.glClearDepth(1.0);

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

        GL11.glCullFace(GL11.GL_FRONT);
        GL11.glEnable(GL11.GL_CULL_FACE);

        }
        
        /**
         * Takes care of setting up necessary objects and creates whatever is needed
         * to run the game
         */
        private void initGame()
        {

                // This is the place to load textures, create necessary data, etc.

        }

        /**
         * Keeps rendering the scene until broken from within.
         */
        private void gameLoop()
        {

                /**
                 * < 1.5: Replace "while (gameState != gameStates.EXIT) {"
                 *           with "while (gameRunning) {"
                 */
                while (gameRunning != false) {

                        if (Display.isCloseRequested()) {

                                /**
                                 * < 1.5: Replace "gameState = gameStates.EXIT;"
                                 *           with "gameRunning = false;"
                                 */

                                gameRunning = false;

                        } else if (Display.isActive()) {

                                handleInput();
                                render();
                                Display.sync(FRAMERATE);

                        } else {

                                handleInput();
                                if (Display.isVisible() || Display.isDirty())
                                        render();

                        }

                        Display.update();

                }

        }

        /**
         * Check for mouse and/or keyboard input and act accordingly.
         */
        private void handleInput()
        {

                /**
                 * Instantly exit the game when ESC is pressed
                 *
                 * < 1.5: Replace "gameState = gameStates.EXIT;"
                 *           with "gameRunning = false;"
                 */
                if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
                        gameRunning = false;

                /**
                 * Switch between fullscreen and windowed mode when F1 is pressed
                 */
                if (Keyboard.isKeyDown(Keyboard.KEY_F1)) {

                        fullscreen = !fullscreen;

                        try {
                                Display.setFullscreen(fullscreen);
                        } catch (Exception e) {
                                e.printStackTrace(System.err);
                                Sys.alert(GAME_TITLE + " - Error", "Unable to switch to " +
                                        ((fullscreen) ? "fullscreen" : "windowed") + " mode.");
                                System.exit(0);
                        }

                }

        }

        /**
         * Renders the scene.
         */
        private void render()
        {

              GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
            // Render your scene here
              
              
              // http://nehe.gamedev.net/ test "copy'n'paste" Coding ^^
              
              GL11.glLoadIdentity();                                                // Reset The View
              
              GL11.glTranslatef(-1.5f,0.0f,-6.0f);                        // Move Left 1.5 Units And 6.0 Into The Screen 
              
              GL11.glBegin(GL11.GL_TRIANGLES);                              // Drawing Using Triangles
                    GL11.glColor3f(1.0f,1.0f,1.0f);                              // Set The Color To White
                    
                    GL11.glVertex3f( 0.0f, 1.0f, 0.0f);                        // Top
                    GL11.glVertex3f(-1.0f,-1.0f, 0.0f);                        // Bottom Left
                    GL11.glVertex3f( 1.0f,-1.0f, 0.0f);                        // Bottom Right
                GL11.glEnd();      
                
        }

}

Looks remarkably like you’re trying to render a tiny, sub-pixel-sized triangle in the bottom left of the screen.

Cas :slight_smile:

Also, looks like your winding order is wrong - once you fix the above, try swapping the two latter vertices over.