Hello Guest

Error 65543

  • 5 Replies
  • 8463 Views
Error 65543
« on: December 14, 2014, 14:40:12 »
Hello everyone,

I downloaded the file at the end of the page from this tutorial, and tried to run it. But this error came up :

ERROR: 65543
Exception in thread "main" java.lang.AssertionError: Failed to create the GLFW window
   at demo01.Demo01.init(Demo01.java:71)
   at demo01.Demo01.run(Demo01.java:304)
   at demo01.Demo01.main(Demo01.java:317)


Has anyone an idea how to correct this ?

Here is the code :
Code: [Select]
package demo01;

import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;

import javax.vecmath.Vector3f;

import org.lwjgl.BufferUtils;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.glfw.GLFWKeyCallback;
import org.lwjgl.glfw.GLFWvidmode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL15;
import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL30;
import org.lwjgl.opengl.GL42;
import org.lwjgl.opengl.GL43;
import org.lwjgl.opengl.GLContext;
import org.lwjgl.system.MemoryUtil;

public class Demo01 {

   private long window;
   private int width = 1024;
   private int height = 768;

   private int tex;
   private int vao;
   private int computeProgram;
   private int quadProgram;

   private int eyeUniform;
   private int ray00Uniform;
   private int ray10Uniform;
   private int ray01Uniform;
   private int ray11Uniform;

   private int workGroupSizeX;
   private int workGroupSizeY;

   private Camera camera;

   private final Vector3f eyeRay = new Vector3f();

   GLFWErrorCallback errFun;
   GLFWKeyCallback keyFun;

   private void init() throws IOException {
      GLFW.glfwSetErrorCallback(errFun = new GLFWErrorCallback() {
         public void invoke(int error, long description) {
            System.err.println("ERROR: " + error);
         }
      });

      if (GLFW.glfwInit() != GL11.GL_TRUE)
         throw new IllegalStateException("Unable to initialize GLFW");

      GLFW.glfwDefaultWindowHints();
      GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE, GLFW.GLFW_OPENGL_CORE_PROFILE);
      GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_FORWARD_COMPAT, GL11.GL_TRUE);
      GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, 4);
      GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, 3);
      GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, GL11.GL_FALSE);
      GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE, GL11.GL_FALSE);

      window = GLFW.glfwCreateWindow(width, height, "Demo01", MemoryUtil.NULL, MemoryUtil.NULL);
      if (window == MemoryUtil.NULL) {
         throw new AssertionError("Failed to create the GLFW window");
      }

      GLFW.glfwSetKeyCallback(window, keyFun = new GLFWKeyCallback() {
         public void invoke(long window, int key, int scancode, int action, int mods) {
            if (key == GLFW.GLFW_KEY_ESCAPE && action == GLFW.GLFW_RELEASE)
               GLFW.glfwSetWindowShouldClose(window, GL11.GL_TRUE);
         }
      });

      ByteBuffer vidmode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor());
      GLFW.glfwSetWindowPos(window, (GLFWvidmode.width(vidmode) - width) / 2,
            (GLFWvidmode.height(vidmode) - height) / 2);
      GLFW.glfwMakeContextCurrent(window);
      GLFW.glfwSwapInterval(1);
      GLFW.glfwShowWindow(window);
      GLContext.createFromCurrent();

      /* Create all needed GL resources */
      tex = createFramebufferTexture();
      vao = quadFullScreenVao();
      computeProgram = createComputeProgram();
      initComputeProgram();
      quadProgram = createQuadProgram();
      initQuadProgram();

      /* Setup camera */
      camera = new Camera();
      camera.setFrustumPerspective(60.0f, (float) width / height, 1f, 2f);
      camera.setLookAt(new Vector3f(3.0f, 2.0f, 7.0f), new Vector3f(0.0f, 0.5f, 0.0f), new Vector3f(0.0f, 1.0f, 0.0f));
   }

   /**
    * Creates a VAO with a full-screen quad VBO.
    */
   private int quadFullScreenVao() {
      int vao = GL30.glGenVertexArrays();
      int vbo = GL15.glGenBuffers();
      GL30.glBindVertexArray(vao);
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
      ByteBuffer bb = BufferUtils.createByteBuffer(4 * 2 * 6);
      bb.putFloat(-1.0f).putFloat(-1.0f);
      bb.putFloat(1.0f).putFloat(-1.0f);
      bb.putFloat(1.0f).putFloat(1.0f);
      bb.putFloat(1.0f).putFloat(1.0f);
      bb.putFloat(-1.0f).putFloat(1.0f);
      bb.putFloat(-1.0f).putFloat(-1.0f);
      bb.flip();
      GL15.glBufferData(GL15.GL_ARRAY_BUFFER, bb, GL15.GL_STATIC_DRAW);
      GL20.glEnableVertexAttribArray(0);
      GL20.glVertexAttribPointer(0, 2, GL11.GL_FLOAT, false, 0, 0L);
      GL30.glBindVertexArray(0);
      return vao;
   }

   /**
    * Create a shader object from the given classpath resource.
    *
    * @param resource
    *            the class path
    * @param type
    *            the shader type
    * @return the shader object id
    * @throws IOException
    */
   private int createShader(String resource, int type) throws IOException {
      int shader = GL20.glCreateShader(type);
      InputStream is = Demo01.class.getResourceAsStream(resource);
      GL20.glShaderSource(shader, Util.getCode(is));
      is.close();
      GL20.glCompileShader(shader);
      int compiled = GL20.glGetShaderi(shader, GL20.GL_COMPILE_STATUS);
      String shaderLog = GL20.glGetShaderInfoLog(shader);
      if (shaderLog.trim().length() > 0) {
         System.err.println(shaderLog);
      }
      if (compiled == 0) {
         throw new AssertionError("Could not compile shader");
      }
      return shader;
   }

   /**
    * Create the full-scren quad shader.
    *
    * @return that program id
    * @throws IOException
    */
   private int createQuadProgram() throws IOException {
      int quadProgram = GL20.glCreateProgram();
      int vshader = createShader("quad.vs", GL20.GL_VERTEX_SHADER);
      int fshader = createShader("quad.fs", GL20.GL_FRAGMENT_SHADER);
      GL20.glAttachShader(quadProgram, vshader);
      GL20.glAttachShader(quadProgram, fshader);
      GL20.glBindAttribLocation(quadProgram, 0, "vertex");
      GL30.glBindFragDataLocation(quadProgram, 0, "color");
      GL20.glLinkProgram(quadProgram);
      int linked = GL20.glGetProgrami(quadProgram, GL20.GL_LINK_STATUS);
      String programLog = GL20.glGetProgramInfoLog(quadProgram);
      if (programLog.trim().length() > 0) {
         System.err.println(programLog);
      }
      if (linked == 0) {
         throw new AssertionError("Could not link program");
      }
      return quadProgram;
   }

   /**
    * Create the tracing compute shader program.
    *
    * @return that program id
    * @throws IOException
    */
   private int createComputeProgram() throws IOException {
      int program = GL20.glCreateProgram();
      int cshader = createShader("demo01.glslcs", GL43.GL_COMPUTE_SHADER);
      GL20.glAttachShader(program, cshader);
      GL20.glLinkProgram(program);
      int linked = GL20.glGetProgrami(program, GL20.GL_LINK_STATUS);
      String programLog = GL20.glGetProgramInfoLog(program);
      if (programLog.trim().length() > 0) {
         System.err.println(programLog);
      }
      if (linked == 0) {
         throw new AssertionError("Could not link program");
      }
      return program;
   }

   /**
    * Initialize the full-screen-quad program.
    */
   private void initQuadProgram() {
      GL20.glUseProgram(quadProgram);
      int texUniform = GL20.glGetUniformLocation(quadProgram, "tex");
      GL20.glUniform1i(texUniform, 0);
      GL20.glUseProgram(0);
   }

   /**
    * Initialize the compute shader.
    */
   private void initComputeProgram() {
      GL20.glUseProgram(computeProgram);
      IntBuffer workGroupSize = BufferUtils.createIntBuffer(3);
      GL20.glGetProgram(computeProgram, GL43.GL_COMPUTE_WORK_GROUP_SIZE, workGroupSize);
      workGroupSizeX = workGroupSize.get(0);
      workGroupSizeY = workGroupSize.get(1);
      eyeUniform = GL20.glGetUniformLocation(computeProgram, "eye");
      ray00Uniform = GL20.glGetUniformLocation(computeProgram, "ray00");
      ray10Uniform = GL20.glGetUniformLocation(computeProgram, "ray10");
      ray01Uniform = GL20.glGetUniformLocation(computeProgram, "ray01");
      ray11Uniform = GL20.glGetUniformLocation(computeProgram, "ray11");
      GL20.glUseProgram(0);
   }

   /**
    * Create the texture that will serve as our framebuffer.
    *
    * @return the texture id
    */
   private int createFramebufferTexture() {
      int tex = GL11.glGenTextures();
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
      ByteBuffer black = BufferUtils.createByteBuffer(4 * 4 * width * height);
      GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL30.GL_RGBA32F, width, height, 0, GL11.GL_RGBA, GL11.GL_FLOAT, black);
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
      return tex;
   }

   /**
    * Compute one frame by tracing the scene using our compute shader and
    * presenting that image on the screen.
    */
   private void trace() {
      GL20.glUseProgram(computeProgram);

      /* Set viewing frustum corner rays in shader */
      GL20.glUniform3f(eyeUniform, camera.getPosition().x, camera.getPosition().y, camera.getPosition().z);
      camera.getEyeRay(-1, -1, eyeRay);
      GL20.glUniform3f(ray00Uniform, eyeRay.x, eyeRay.y, eyeRay.z);
      camera.getEyeRay(-1, 1, eyeRay);
      GL20.glUniform3f(ray01Uniform, eyeRay.x, eyeRay.y, eyeRay.z);
      camera.getEyeRay(1, -1, eyeRay);
      GL20.glUniform3f(ray10Uniform, eyeRay.x, eyeRay.y, eyeRay.z);
      camera.getEyeRay(1, 1, eyeRay);
      GL20.glUniform3f(ray11Uniform, eyeRay.x, eyeRay.y, eyeRay.z);

      /* Bind level 0 of framebuffer texture as writable image in the shader. */
      GL42.glBindImageTexture(0, tex, 0, false, 0, GL15.GL_WRITE_ONLY, GL30.GL_RGBA32F);

      /* Compute appropriate invocation dimension. */
      int worksizeX = Util.nextPowerOfTwo(width);
      int worksizeY = Util.nextPowerOfTwo(height);

      /* Invoke the compute shader. */
      GL43.glDispatchCompute(worksizeX / workGroupSizeX, worksizeY / workGroupSizeY, 1);

      /* Reset image binding. */
      GL42.glBindImageTexture(0, 0, 0, false, 0, GL15.GL_READ_WRITE, GL30.GL_RGBA32F);
      GL42.glMemoryBarrier(GL42.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
      GL20.glUseProgram(0);

      /*
       * Draw the rendered image on the screen using textured full-screen
       * quad.
       */
      GL20.glUseProgram(quadProgram);
      GL30.glBindVertexArray(vao);
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex);
      GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 6);
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
      GL30.glBindVertexArray(0);
      GL20.glUseProgram(0);
   }

   private void loop() {
      while (GLFW.glfwWindowShouldClose(window) == GL11.GL_FALSE) {
         GLFW.glfwPollEvents();
         GL11.glViewport(0, 0, width, height);

         System.gc();
         trace();

         GLFW.glfwSwapBuffers(window);
      }
   }

   private void run() {
      try {
         init();
         loop();
         errFun.release();
         keyFun.release();
         GLFW.glfwDestroyWindow(window);
      } catch (Exception e) {
         e.printStackTrace();
      } finally {
         GLFW.glfwTerminate();
      }
   }

   public static void main(String[] args) {
      new Demo01().run();
   }

}


Thank you in advance,


Maxime

*

Kai

Re: Error 65543
« Reply #1 on: December 14, 2014, 14:47:12 »
Hello Maxime,

I'm sorry that you get this error, since it seems, that your graphics driver does not support OpenGL 4.3.

What graphics card do you use and what driver version is installed?
Maybe switching to the latest driver version will fix this. If you have a Nvidia GPU with a Kepler chip, then it definitely should support that OpenGL version.

Kai

EDIT: The tutorial sources and binaries have been updated for better GLFW error reporting.
« Last Edit: December 14, 2014, 15:13:18 by Kai »

Re: Error 65543
« Reply #2 on: December 14, 2014, 16:27:51 »
Hello Kai,

The graphics card is the Intel HD Graphics 3000 and I'm running the latest patch on my mac. I never heard of drivers for graphics card on a mac, but I'll look for it :)

Thank you

Edit: Here is the error I get with the new code :

[LWJGL] GLFW_VERSION_UNAVAILABLE error
   Description : The requested client API version is unavailable
   Stacktrace  :
      org.lwjgl.glfw.GLFW.nglfwCreateWindow(Native Method)
      org.lwjgl.glfw.GLFW.glfwCreateWindow(GLFW.java:991)
      demo01.Demo01.init(Demo01.java:72)
      demo01.Demo01.run(Demo01.java:306)
      demo01.Demo01.main(Demo01.java:319)
Exception in thread "main" java.lang.AssertionError: Failed to create the GLFW window
   at demo01.Demo01.init(Demo01.java:74)
   at demo01.Demo01.run(Demo01.java:306)
   at demo01.Demo01.main(Demo01.java:319)

« Last Edit: December 14, 2014, 16:33:13 by Maxime »

*

Kai

Re: Error 65543
« Reply #3 on: December 14, 2014, 16:38:05 »
Okay, here is the source of the problem:

According to Wikipedia http://en.wikipedia.org/wiki/List_of_Intel_graphics_processing_units the HD 3000 card only supports OpenGL up to version 3.3.  :(

So, I'm really sorry, but it seems that you will not be able to run (at least) this demo on that machine.

But because of this, and also because of Apple in general only supporting up to OpenGL 4.1 even on their very latest hardware, I am planning on porting that particular demo to OpenGL 3.1 with vertex and fragment shaders - so doing it the goold old GPGPU way.
I guess, Apple is to blame for this one.  ;)

But any further tutorials within that ray tracing tutorial will again use OpenGL 4.3, since that version for the first time introduced a way to handle large amounts of arbitrarily structured data streams with Shader Storage Buffer Objects (SSBOs).

So, the only thing left for me to tell you is, thanks for reading the tutorial and trying out the demo, and also sorry, because as it stands, this particular demo application will not run on your machine. :(

Regards,
Kai

Re: Error 65543
« Reply #4 on: December 14, 2014, 17:04:18 »
That's too bad  :-\  thank you for answering me in a very short amount of time.

 I'll buy a new computer in a few months. And in the meantime, I'll be looking forward your demo ported to OpenGL 3.1 ;)

Best Regards,
Maxime

*

Kai

Re: Error 65543
« Reply #5 on: December 14, 2014, 17:16:34 »
The tutorial sources and binary jars have been updated with an additional package "demo01_30" that is a port of the "demo01" using old-style GPGPU full-screen quad rendering with vertex/fragment shaders to trace the scene. It produces the exact same output as does the Compute Shader version, but using the other technique.

EDIT: due to the Content Distribution Network caching the old zip, you may have to wait until tomorrow before the old tutorial zip is replaced with the new one.
« Last Edit: December 14, 2014, 17:30:14 by Kai »