Problem setting up display with core profile and forward compatability

Started by jentz, February 12, 2011, 18:22:39

Previous topic - Next topic

jentz

I am trying to learn OpenGL 3.3+ using the OprnGL SuperBible 5th Edition and LWJGL. I'm using Windows 7 x64 and have an ATI HD4870x2 with the Catalyst 11.1 drivers.

The code below is failing with the call to GL11.glClearColor(0f, 0f, 1f, 0f);.  I'm running the program with -Dorg.lwjgl.util.Debug=true and using lwjgl-debug.jar.

package net.jentz;

import org.lwjgl.Sys;
import org.lwjgl.input.Keyboard;
import org.lwjgl.openal.AL;
import org.lwjgl.opengl.ContextAttribs;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.PixelFormat;

public class Ogl33 {

  /** Game title */
  public static final String GAME_TITLE = "Ogl33";

  private static final boolean CTX_DEBUG = true;

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

  /**
   * Application init
   * 
   * @param args Commandline args
   */
  public static void main(String[] args) {
    try {
      init();
      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);
  }
  
  /**
   * Initialize the game
   * 
   * @throws Exception if init fails
   */
  private static void init() throws Exception {
    Display.setTitle(GAME_TITLE);
    Display.setFullscreen(false);
    Display.setDisplayMode(new DisplayMode(1024, 768));

    // Setup OpenGL 3.3 forward-compatible core profile 
    ContextAttribs ctxAttr = new ContextAttribs(3, 3);
    ctxAttr = ctxAttr.withForwardCompatible(true).withProfileCore(true).withProfileCompatibility(false).withDebug(CTX_DEBUG);

    PixelFormat pf = new PixelFormat(8, 0, 24, 8, 4);
    Display.create(pf, ctxAttr);
    GL11.glClearColor(0f, 0f, 1f, 0f);
    
    // Start up the sound system
    AL.create();
  }

  /**
   * Runs the game (the "main loop")
   */
  private static void run() {
    while (!finished) {
      // Always call Window.update(), all the time
      Display.update();

      if (Display.isCloseRequested()) {
        // Check for O/S close requests
        finished = true;
      }
      else if (Display.isActive()) {
        // The window is in the foreground, so we should play the game
        logic();
        render();
       // Display.sync(FRAMERATE);
      }
      else {
        // The window is not in the foreground, so we can allow other stuff to run and
        // infrequently update
        try {
          Thread.sleep(100);
        }
        catch (InterruptedException e) {
        }
        logic();
        if (Display.isVisible() || Display.isDirty()) {
          // Only bother rendering if the window is visible or dirty
          render();
        }
      }
    }
  }

  /**
   * Do any game-specific cleanup
   */
  private static void cleanup() {
    // Stop the sound
    AL.destroy();

    // Close the window
    Display.destroy();
  }

  /**
   * Do all calculations, handle input, etc.
   */
  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;
    }
  }

  /**
   * Render the current frame
   */
  private static void render() {
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);
  }
}


Initial mode: 1920 x 1200 x 32 @59Hz
org.lwjgl.opengl.OpenGLException: Invalid enum (1280)
	at org.lwjgl.opengl.Util.checkGLError(Util.java:59)
	at org.lwjgl.opengl.GL11.glClearColor(GL11.java:575)
	at net.jentz.Ogl33.init(Ogl33.java:59)
	at net.jentz.Ogl33.main(Ogl33.java:29)
*** Alert ***Ogl33
An error occured and the game will exit.

Could not locate symbol glEnableClientStateiEXT
Could not locate symbol glDisableClientStateiEXT
Could not locate symbol glGetFloati_vEXT
Could not locate symbol glGetDoublei_vEXT
Could not locate symbol glGetPointeri_vEXT
Could not locate symbol glVertexWeighthNV
Could not locate symbol glVertexAttrib1hNV
Could not locate symbol glVertexAttrib2hNV
Could not locate symbol glVertexAttrib3hNV
Could not locate symbol glVertexAttrib4hNV
Could not locate symbol glVertexAttribs1hvNV
Could not locate symbol glVertexAttribs2hvNV
Could not locate symbol glVertexAttribs3hvNV
Could not locate symbol glVertexAttribs4hvNV


Changing from
ctxAttr = ctxAttr.withForwardCompatible(true).withProfileCore(true).withProfileCompatibility(false).withDebug(CTX_DEBUG);

to
ctxAttr = ctxAttr.withForwardCompatible(false).withProfileCore(true).withProfileCompatibility(true).withDebug(CTX_DEBUG);

works, but I am under the impression that it should work either way. since glClearColor() exists in the core profile.

Estraven

Hello, I know the topic is quite old, but in case the problem remains...

i think that the problem arise from the use of EXT symbols

"Could not locate symbol glEnableClientStateiEXT"

In Core profile, use Core function glEnableClientState() (no EXT)

Estraven


spasi

Nah, that message is related to a missing entry point in the AMD driver, you see it when running with Debug=true.

Anyway, this is indeed an old post, but I've tried the code above and it works with the latest AMD driver and LWJGL version. Also, I don't think the problem was related to glClearColor, since you can't get Invalid enum (1280) from that. Util.checkGLError was probably catching an error that occurred before it.