Issues with GL11 functions in Netbeans project

Started by ligaa9mm, January 01, 2011, 10:23:13

Previous topic - Next topic


Hey everyone! Complete LWJGL newbie here.

I followed the tutorials on the wiki to set up my Netbeans project, and started working with the Space Invaders demo. I didn't add much of the actual game elements, but instead opted to strip it out to a basic shell that I could start making a first person shooter with. I'm at the point where I can open a window with a black screen (hooray!), but can't get much further.

What happens is Netbeans yells at me because it can't find the declarations for the glClear, glMatrixMode, and glLoadIdentity functions in the gameLoop function in the Space Invaders tutorial. It also has problems with GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, and GL_MODELVIEW. The comments on the tutorial say those are needed to "clear screen", so it sounds like I will need those for my game to function properly. I haven't gone much further than this in the code.
I checked the Java docs, and the aforementioned functions and variables are built into the GL11 class structure, and they are public. When I input the class, I do it just like the tutorial:
import org.lwjgl.opengl.GL11.*;

I notice, however, that after trying to auto-complete after "GL11", I get "No suggestions". I think that is the main part of the problem. If I go down to, say, glClear() and add "org.lwjgl.opengl.GL11." to the front of it, it works fine. I've seen this behavior in Flex before, where more than one class package has the same function defined, and you have to specify which it is that you want. Is there a different class I should be using? Do I really need to define each function every time I try to use GL11?

Here's the full code I have so far:
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
package simpleshooter;

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 org.lwjgl.opengl.GL11.*;

public class Game {

    private String WINDOW_TITLE = "Simple Shooter";
    private int WINDOW_WIDTH = 800;
    private int WINDOW_HEIGHT = 600;
    private boolean fullscreen;
    private SoundManager soundManager;
    public static boolean gameRunning = true;
    private static boolean isApplication;
    private static long timerTicksPerSecond = Sys.getTimerResolution();
    private long lastFpsTime;
    private int fps;
    private long lastLoopTime = getTime();

    public static void main(String[] args) {
        isApplication = true;
        System.out.println("Use -fullscreen for fullscreen mode");
        new Game((args.length > 0 && "-fullscreen".equalsIgnoreCase(args[0]))).execute();

    public Game(boolean fullscreen) {
        this.fullscreen = fullscreen;

    public void initialize() {
        try {

            if (isApplication) {

            soundManager = new SoundManager();
        } catch (LWJGLException le) {
            System.out.println("Game exiting - exception in initialization:");
            Game.gameRunning = false;

    private boolean setDisplayMode() {
        try {
            // get modes
            DisplayMode[] dm = org.lwjgl.util.Display.getAvailableDisplayModes(WINDOW_WIDTH, WINDOW_HEIGHT, -1, -1, -1, -1, 60, 60);

            org.lwjgl.util.Display.setDisplayMode(dm, new String[]{
                        "width=" + WINDOW_WIDTH,
                        "height=" + WINDOW_HEIGHT,
                        "freq=" + 60,
                        "bpp=" + org.lwjgl.opengl.Display.getDisplayMode().getBitsPerPixel()
            return true;
        } catch (Exception e) {
            System.out.println("Unable to enter fullscreen, continuing in windowed mode");

        return false;

    public void execute() {

    private void gameLoop() {
        while (Game.gameRunning) {
            // clear screen

            // let subsystem paint

            // update window contents

        // clean up

    public void frameRendering() {

        // work out how long its been since the last update, this
        // will be used to calculate how far the entities should
        // move this loop
        long delta = getTime() - lastLoopTime;
        lastLoopTime = getTime();
        lastFpsTime += delta;

        // update our FPS counter if a second has passed
        if (lastFpsTime >= 1000) {
            Display.setTitle(WINDOW_TITLE + " (FPS: " + fps + ")");
            lastFpsTime = 0;
            fps = 0;

        // if escape has been pressed, stop the game
        if ((Display.isCloseRequested() || Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) && isApplication) {
            Game.gameRunning = false;

    public static long getTime() {
        // we get the "timer ticks" from the high resolution timer
        // multiply by 1000 so our end result is in milliseconds
        // then divide by the number of ticks in a second giving
        // us a nice clear time in milliseconds
        return (Sys.getTime() * 1000) / timerTicksPerSecond;

    public static void sleep(long duration) {
        try {
            Thread.sleep((duration * timerTicksPerSecond) / 1000);
        } catch (InterruptedException inte) {

Thanks for the help!


import static org.lwjgl.opengl.GL11.*;

or better to just call the GL functions like this:
import org.lwjgl.opengl.GL11;



Okay now I'm having a different, but similar problem. I'm trying to use gluPerspective(), and I've found it in the section org.lwjgl.util.glu.Util. I already have the function in my code. But when I try either of these options to import it, it either tells me that the import is not used and has an error for the function, or tells me it can't find the import:

import org.lwjgl.util.glu.Util; //unused import
import static org.lwjgl.util.glu.*; //cannot find symbol glu

I should mention that the tutorial I'm following (lesson 05) imports the gluPerspective() function from org.lwjgl.opengl.glu.GLU.

What am I doing wrong? And what can I do to avoid this problem in the future?


If you look at the example code at the end of the NetBeans tutorial ( here ), this how you need to specify a static import with glu:

import static org.lwjgl.util.glu.GLU.*;
cool story, bro