Hello Guest

(Solved)(Black screen) AWTCanvas won't display until resized on MacOSX

  • 5 Replies
  • 3542 Views
Hello,

I'm trying to make an applet with lwjgl, that i need to work on windows and mac osx
I have made a first try with a spinning cube that work perfectly on windows.

But when i try to start from a mac, i only have a full black screen.
I didn't manage to have even the good clear color...

Every other thing work, i can display the shader's in/out indeces, which show that the shaders are compiled and linked. I can also display the key and mouse event which show that the main loop is running.

I have trying to display full opengl log and error checking after each line, but can't find anything going wrong.

I'm out of ideas, so I hope somebody could what i made wrong.

The code is targetted for opengl 3.2 with glsl 1.5, both supported by the test laptop

Here, the test applet which work on windows (manifest is not fully declared, so java ask to trust the code at the start): http://www.*********.com/~ohmydressing/

and here the relevent part (i think) of the code.

Creation of the display:

Code: [Select]
glCanvas = new AWTGLCanvas () {
@Override
public final void addNotify(){
super.addNotify();
}
@Override
public final void removeNotify(){
stopLWJGL();
super.removeNotify();
}
};

glCanvas.setVisible(true);

ContextAttribs context = new ContextAttribs(3,2).withProfileCore(true).withDebug(true);
Display.setParent(glCanvas);
Display.create(new PixelFormat(32, 0, 24, 0, 2),context);


the initialisation with cube creation:

Code: [Select]
System.out.println("GL_RENDERER  = " + GL11.glGetString(GL11.GL_RENDERER));
System.out.println("GL_VERSION   = " + GL11.glGetString(GL11.GL_VERSION));
System.out.println("GLSL_VERSION = " + GL11.glGetString(GL20.GL_SHADING_LANGUAGE_VERSION));

programShader = loadShader();

float[] test1 = new float[]{
-10.0f,  10.0f,  10.0f,   0.0f,  0.0f,  1.0f,   0.0f,  0.0f,
-10.0f, -10.0f,  10.0f,   0.0f,  0.0f,  1.0f,   0.0f,  1.0f,
10.0f,  10.0f,  10.0f,   0.0f,  0.0f,  1.0f,   1.0f,  0.0f,

-10.0f, -10.0f,  10.0f,   0.0f,  0.0f,  1.0f,   0.0f,  1.0f,
10.0f, -10.0f,  10.0f,   0.0f,  0.0f,  1.0f,   1.0f,  1.0f,
10.0f,  10.0f,  10.0f,   0.0f,  0.0f,  1.0f,   1.0f,  0.0f,
//-
-10.0f, -10.0f,  10.0f,   0.0f, -1.0f,  0.0f,   0.0f,  0.0f,
-10.0f, -10.0f, -10.0f,   0.0f, -1.0f,  0.0f,   0.0f,  1.0f,
10.0f, -10.0f,  10.0f,   0.0f, -1.0f,  0.0f,   1.0f,  0.0f,

-10.0f, -10.0f, -10.0f,   0.0f, -1.0f,  0.0f,   0.0f,  1.0f,
10.0f, -10.0f, -10.0f,   0.0f, -1.0f,  1.0f,   1.0f,  1.0f,
10.0f, -10.0f,  10.0f,   0.0f, -1.0f,  0.0f,   1.0f,  0.0f,
//-
-10.0f, -10.0f, -10.0f,   0.0f,  0.0f, -1.0f,   0.0f,  0.0f,
-10.0f,  10.0f, -10.0f,   0.0f,  0.0f, -1.0f,   0.0f,  1.0f,
10.0f, -10.0f, -10.0f,   0.0f,  0.0f, -1.0f,   1.0f,  0.0f,

-10.0f,  10.0f, -10.0f,   0.0f,  0.0f, -1.0f,   0.0f,  1.0f,
10.0f,  10.0f, -10.0f,   0.0f,  0.0f, -1.0f,   1.0f,  1.0f,
10.0f, -10.0f, -10.0f,   0.0f,  0.0f, -1.0f,   1.0f,  0.0f,
//-
-10.0f,  10.0f, -10.0f,   0.0f,  1.0f,  0.0f,   0.0f,  0.0f,
-10.0f,  10.0f,  10.0f,   0.0f,  1.0f,  0.0f,   0.0f,  1.0f,
10.0f,  10.0f, -10.0f,   0.0f,  1.0f,  0.0f,   1.0f,  0.0f,

-10.0f,  10.0f,  10.0f,   0.0f,  1.0f,  0.0f,   0.0f,  1.0f,
10.0f,  10.0f,  10.0f,   0.0f,  1.0f,  0.0f,   1.0f,  1.0f,
10.0f,  10.0f, -10.0f,   0.0f,  1.0f,  0.0f,   1.0f,  0.0f,
//-
-10.0f, -10.0f,  10.0f,  -1.0f,  0.0f,  0.0f,   0.0f,  0.0f,
-10.0f,  10.0f,  10.0f,  -1.0f,  0.0f,  0.0f,   0.0f,  1.0f,
-10.0f, -10.0f, -10.0f,  -1.0f,  0.0f,  0.0f,   1.0f,  0.0f,

-10.0f,  10.0f,  10.0f,  -1.0f,  0.0f,  0.0f,   0.0f,  1.0f,
-10.0f,  10.0f, -10.0f,  -1.0f,  0.0f,  0.0f,   1.0f,  1.0f,
-10.0f, -10.0f, -10.0f,  -1.0f,  0.0f,  0.0f,   1.0f,  0.0f,

10.0f, -10.0f, -10.0f,   1.0f,  0.0f,  0.0f,   0.0f,  0.0f,
10.0f,  10.0f, -10.0f,   1.0f,  0.0f,  0.0f,   0.0f,  1.0f,
10.0f, -10.0f,  10.0f,   1.0f,  0.0f,  0.0f,   1.0f,  0.0f,

10.0f,  10.0f, -10.0f,   1.0f,  0.0f,  0.0f,   0.0f,  1.0f,
10.0f,  10.0f,  10.0f,   1.0f,  0.0f,  0.0f,   1.0f,  1.0f,
10.0f, -10.0f,  10.0f,   1.0f,  0.0f,  0.0f,   1.0f,  0.0f,
};

vao0 = GL30.glGenVertexArrays();
GL30.glBindVertexArray(vao0);

meshArray0 = GL15.glGenBuffers();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, meshArray0);

FloatBuffer vertices1 = BufferUtils.createFloatBuffer(test1.length);
vertices1.put(test1);
vertices1.flip();


GL15.glBufferData(GL15.GL_ARRAY_BUFFER,vertices1, GL15.GL_STATIC_DRAW);

if (AttribPosColor>=0){
GL20.glEnableVertexAttribArray(AttribPosColor); // pos
GL20.glVertexAttribPointer(AttribPosColor,3,GL11.GL_FLOAT,false,8*4,0);
}
if (AttribNormColor>=0){
GL20.glEnableVertexAttribArray(AttribNormColor); // normal
GL20.glVertexAttribPointer(AttribNormColor,3,GL11.GL_FLOAT,false,8*4,3*4);
}
if (AttribTexPosColor>=0){
GL20.glEnableVertexAttribArray(AttribTexPosColor); // tex
GL20.glVertexAttribPointer(AttribTexPosColor,2,GL11.GL_FLOAT,false,8*4,6*4);
}

GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);


GL30.glBindVertexArray(0);

GL11.glClearColor(1.0f, 0.5f, 0.5f, 0.0f);

the display loop:

Code: [Select]
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

programShader.bind();

GL20.glUniformMatrix4(MVPDepth, false, mvpf);

GL30.glBindVertexArray(vao0);
GL20.glEnableVertexAttribArray(0);
GL11.glDrawArrays(GL11.GL_TRIANGLES,0,36);
GL20.glDisableVertexAttribArray(0);
GL30.glBindVertexArray(0);

programShader.unbind();

and the shaders:
Code: [Select]
//vertex shader:

#version 150

uniform mat4 ModelViewProjection;

in vec3 mPosition;
in vec3 mNormal;
in vec2 mTexCoord;

out vec4 initial_position;
out vec4 projected_position;
out vec2 vTexCoord;
out vec3 vTangeant;

void main()
{
gl_Position = ModelViewProjection * vec4(mPosition,1);
projected_position = gl_Position;
initial_position = vec4(mPosition,1);
vTexCoord = mTexCoord;
vec4 projNormal = ModelViewProjection * vec4(mNormal,0);
projNormal /= projNormal.w;
vTangeant = projNormal.xyz;
}
//----------------------------------------------------------------------------
//fragment shader:

#version 150

uniform sampler2D myTexture;
uniform sampler2D depthVisibility;

in vec4 projected_position;
in vec2 vTexCoord;
in vec3 vTangeant;

out vec4 outFragColor;

void main()
{
outFragColor = projected_position;
}

I hope i don't forget any usefull information.
PS: English is not my language, i hope everything is understandable.
« Last Edit: March 16, 2015, 12:04:38 by APGenesis »

Re: Black screen on MacOSX
« Reply #1 on: March 13, 2015, 16:13:55 »
After days of headeach, i had the idea to take a screenshoot of the black screen, and it contains the display that i want...

So Opengl compute the good image, but macos don't update the canvas with it.

Is there any known issues about awtcanvas and osx ?

Re: Black screen on MacOSX
« Reply #2 on: March 13, 2015, 18:40:02 »
Some more test show that the problem comes from my canvas, but i don't see why it won't display my content...

Code: [Select]
        try{
            glCanvas = new AWTGLCanvas () {
                @Override
                public final void addNotify(){
                    super.addNotify();
                }
                @Override
                public final void removeNotify(){
                    stopLWJGL();
                    super.removeNotify();
                }
            };
            glCanvas.setSize(getWidth(), getHeight());
            add(glCanvas);
            glCanvas.setFocusable(true);
            glCanvas.requestFocus();
            glCanvas.setIgnoreRepaint(true);
            glCanvas.setVisible(true);
                   
            ContextAttribs context = new ContextAttribs(3,2).withProfileCore(true).withDebug(true);
            Display.setParent(glCanvas);
            Display.create(new PixelFormat(32, 0, 24, 0, 2),context);           


        }catch(Exception e){
            throw new RuntimeException("Impossible de créer le Canvas LWJGL - " + e.getLocalizedMessage());
        }



If i start in a frame, i have a blank screen until resized it.
If i use the default lwjglframe it work too, unfortunately i can't keep it as this...

Any idea ?

Re: (Black screen) AWTCanvas won't display until resized on MacOSX
« Reply #3 on: March 15, 2015, 08:34:57 »
I had the same issue a few months ago. Though it was happening on both platform, osx and win. I solved it by the following way :
Try with a BorderLayout layout manager. Also check if you run Display.create() in the same code block - that's the same thread - it'll overlap with the AWT Dispatcher thread.
For instance, when you add(canvas) the layout manager notifies the AWT EventQueue (which is another AWT system thread), and you have to let the current thread to finish that before to call Display.create() from LWJGL, whatever thread it is.
 :)

Re: (Black screen) AWTCanvas won't display until resized on MacOSX
« Reply #4 on: March 16, 2015, 12:02:27 »
Ok, it wasn't due to the layout, but your explanation about the threads saved me, thanks ^^

The probleme was that i created the display in the call to applet.init() instead of applet.start().

That's cool , thank you for your feedback ! I'll remind that.