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:
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:
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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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:
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:
//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.