Hello Guest

Issues with GL11 functions in Netbeans project

  • 5 Replies
Issues with GL11 functions in Netbeans project
« on: January 01, 2011, 10:23:13 »
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:
Code: [Select]
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:
Code: [Select]
 * 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!

Re: Issues with GL11 functions in Netbeans project
« Reply #1 on: January 01, 2011, 13:14:11 »
Code: [Select]
import static org.lwjgl.opengl.GL11.*;
or better to just call the GL functions like this:
Code: [Select]
import org.lwjgl.opengl.GL11;

Re: Issues with GL11 functions in Netbeans project
« Reply #2 on: January 01, 2011, 16:41:55 »
Thank you! That did the trick!

Re: Issues with GL11 functions in Netbeans project
« Reply #3 on: January 02, 2011, 00:55:09 »
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:

Code: [Select]
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?
« Last Edit: January 02, 2011, 00:57:39 by ligaa9mm »

Re: Issues with GL11 functions in Netbeans project
« Reply #4 on: January 02, 2011, 03:18:59 »
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

Re: Issues with GL11 functions in Netbeans project
« Reply #5 on: January 05, 2011, 05:15:39 »
Thank you, I did miss that part