LWJGL Forum

Please login or register.

Login with username, password and session length
Pages: 1 ... 8 9 [10]
 91 
 on: February 10, 2017, 15:13:09 
Started by pdid - Last post by Fataho
See GLFW's glfwMakeContextCurrent() documentation. Especially the "chronized blogParameters" section.

Thank you for the hint. It works now. I also had to put everything into synchronized block and use wait and notify. Here is my code:

Code: [Select]
public TexturedModel loadTexturedModelWithSeparateThread(float[] verticesArray
, float[] textureArray
, float[] normalsArray
, int[] indicesArray
, String textureFilePathAndName){

int vaoId = createVAO();
bindVAO(vaoId);
glfwMakeContextCurrent(MemoryUtil.NULL);
new Thread(() -> {
synchronized (this){
glfwMakeContextCurrent(Window.windowID);
GL.createCapabilities();
verticesVBOId = createVBO(verticesArray);
texturesVBOId = createVBO(textureArray);
normalsVBOId = createVBO(normalsArray);
bindIndices(indicesArray);
textureId = loadTexture(textureFilePathAndName);
glfwMakeContextCurrent(MemoryUtil.NULL);
System.out.println("TEST T2");
notify();
}

}).start();
synchronized(this){
try {
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
glfwMakeContextCurrent(Window.windowID);
GL.createCapabilities();
storeDataInAttributeList(verticesVBOId, 0, 3);
storeDataInAttributeList(texturesVBOId, 1, 2);
storeDataInAttributeList(normalsVBOId, 2, 3);
unBindVAO();
System.out.println("TEST T1");
}
return new TexturedModel(vaoId, indicesArray.length, textureId);
}

Output:
Code: [Select]
TEST THREAD 2
TEST THREAD 1

 92 
 on: February 10, 2017, 11:07:56 
Started by pdid - Last post by Kai
See GLFW's glfwMakeContextCurrent() documentation. Especially the "Parameters" section.

 93 
 on: February 10, 2017, 11:04:00 
Started by pdid - Last post by Fataho
How to clear the context on the thread? What command should be used? I try to load info into VBO on separate thread and I am getting similar error. What I am doing wrong?

Code: [Select]
[LWJGL] GLFW_PLATFORM_ERROR error
Description : WGL: Failed to make context current: The requested resource is in use.
Stacktrace  :
org.lwjgl.glfw.GLFW.glfwMakeContextCurrent(GLFW.java:3397)
fataho.engine.Loader.lambda$loadTexturedModelWithSeparateThread$0(Loader.java:68)
java.lang.Thread.run(Thread.java:745)
Exception in thread "Thread-0" java.lang.IllegalStateException: There is no OpenGL context current in the current thread.
at org.lwjgl.opengl.GL.createCapabilities(GL.java:351)
at org.lwjgl.opengl.GL.createCapabilities(GL.java:302)
at fataho.engine.Loader.lambda$loadTexturedModelWithSeparateThread$0(Loader.java:69)
at java.lang.Thread.run(Thread.java:745)
My code:

Code: [Select]
        private int verticesVBOId;
private int texturesVBOId;
private int normalsVBOId;
private int textureId;
public TexturedModel loadTexturedModelWithSeparateThread(float[] verticesArray
, float[] textureArray
, float[] normalsArray
, int[] indicesArray
, String textureFilePathAndName){

int vaoId = createVAO();
bindVAO(vaoId);
new Thread(() -> {
glfwMakeContextCurrent(Window.windowID);
GL.createCapabilities();
verticesVBOId = createVBO(verticesArray);
texturesVBOId = createVBO(textureArray);
normalsVBOId = createVBO(normalsArray);
bindIndices(indicesArray);
textureId = loadTexture(textureFilePathAndName);
}).start();
storeDataInAttributeList(verticesVBOId, 0, 3);
storeDataInAttributeList(texturesVBOId, 1, 2);
storeDataInAttributeList(normalsVBOId, 2, 3);
unBindVAO();

return new TexturedModel(vaoId, indicesArray.length, textureId);
}

        private int createVAO(){
int vaoId = GL30.glGenVertexArrays();
vaoIds.add(vaoId);
return vaoId;
}

private void bindVAO(int vaoId){
GL30.glBindVertexArray(vaoId);
}

private void unBindVAO(){
GL30.glBindVertexArray(0);
}

        private synchronized int createVBO(float[] data){
int vboId = GL15.glGenBuffers();
vaoIds.add(vboId);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
FloatBuffer verticesBuffer = storeDataInFloatBuffer(data);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesBuffer, GL15.GL_STATIC_DRAW);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
return vboId;
}
private synchronized void storeDataInAttributeList(int vboId, int attributeNumber, int coordinateSize){
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
GL20.glVertexAttribPointer(attributeNumber, coordinateSize, GL11.GL_FLOAT, false, 0, 0);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
}

private int loadTexture(String modelFileLocationAndName){
int bytesPerPixel = 4; // 3 for RGB, 4 for RGBA
BufferedImage image = null;
try {
image = ImageIO.read(new File(modelFileLocationAndName));
} catch (IOException e) {
//Error Handling Here
e.printStackTrace();
}int[] pixels = new int[image.getWidth() * image.getHeight()];
image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth());
ByteBuffer buffer = BufferUtils.createByteBuffer(image.getWidth() * image.getHeight() * bytesPerPixel); // 4 for RGBA, 3 for RGB
for(int y = 0; y < image.getHeight(); y++){
for(int x = 0; x < image.getWidth(); x++){
int pixel = pixels[y * image.getWidth() + x];
buffer.put((byte) ((pixel >> 16) & 0xFF));     // Red component
buffer.put((byte) ((pixel >> 8) & 0xFF));      // Green component
buffer.put((byte) (pixel & 0xFF));               // Blue component
buffer.put((byte) ((pixel >> 24) & 0xFF));    // Alpha component. Only for RGBA
}
}
buffer.flip(); //FOR THE LOVE OF GOD DO NOT FORGET THIS
// You now have a ByteBuffer filled with the color data of each pixel.
// Now just create a texture ID and bind it. Then you can load it using
// whatever OpenGL method you want, for example:
int textureID = glGenTextures(); //Generate texture ID
glBindTexture(GL_TEXTURE_2D, textureID); //Bind texture ID
//Setup wrap mode
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
//Setup textureBuffer scaling filtering
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
//Send texel data to OpenGL
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

// Mip mapping
// GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
// GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
// GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, -1); // enter -1 if using Anisotropic filtering, ese -0,4f

// Anisotropic filtering, not sure for 100 %, I can't check compatibility context

float amount = Math.min(4f, GL11.glGetFloat(EXTTextureFilterAnisotropic.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT));
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT, amount);
return textureID;
}


 94 
 on: February 07, 2017, 10:35:41 
Started by TwisterGE - Last post by TwisterGE
Oh....!!!
That's it, it solved my problem, thank you very much!

 95 
 on: February 06, 2017, 20:45:28 
Started by KKSystem - Last post by KKSystem
"'transformDirection()' is just a multiplication of the upper-left 3x3 submatrix with a 3D vector." - can you show me in code how can I do this thing please?
I tried something like this:

Matrix4f cam = Maths.createTransformationMatrix(camera.getPosition(), camera.getRoll(), camera.getPitch(), camera.getYaw(), 1);
Matrix4f invCam;
Matrix4f.invert(cam, invCam);
Vector3f at = new Vector3f(0, 0, -1);
//invCam.transformDirection(at);
Vector3f up = new Vector3f(0, 1, 0);
//invCam.transformDirection(up);

createTransformationMatrix method:
public static Matrix4f createTransformationMatrix(Vector3f translation, float rx, float ry, float rz, float scale)
{
   Matrix4f matrix = new Matrix4f();
   matrix.setIdentity();
   Matrix4f.translate(translation, matrix, matrix);
   Matrix4f.rotate((float) Math.toRadians(rx), new Vector3f(1,0,0), matrix, matrix);
   Matrix4f.rotate((float) Math.toRadians(ry), new Vector3f(0,1,0), matrix, matrix);
   Matrix4f.rotate((float) Math.toRadians(rz), new Vector3f(0,0,1), matrix, matrix);
   Matrix4f.scale(new Vector3f(scale,scale,scale), matrix, matrix);
   return matrix;
}

Thank you for your help :)

 96 
 on: February 06, 2017, 19:24:36 
Started by KKSystem - Last post by Kai
'transformDirection()' is just a multiplication of the upper-left 3x3 submatrix with a 3D vector.
And you also only need 'invert()' additionally. See the first code snippet of the referenced post.
What you generally need to do (which is also described in the referenced forum post) is to transform the base axes of the camera/eye-space into world-space and use those for OpenAL's AL_ORIENTATION.
Also, AL_DIRECTION is not defined for the listener. It is only used for the source.

 97 
 on: February 06, 2017, 19:03:34 
Started by KKSystem - Last post by KKSystem
I don't have the functions:
transformDirection
positiveZ
positiveY
In my Matrix4f objects, so it doesn't works for me :(

My camera objects:
private Vector3f _position = new Vector3f(0, 40f, 0);
private float _pitch;
private float _yaw;
private float _roll;

Set listener datat method:
public static void setListenerData(float x, float y, float z, float directionX, float directionY, float directionZ)
{
   AL10.alListener3f(AL10.AL_POSITION, x, y, z);
   AL10.alListener3f(AL10.AL_VELOCITY, 0, 0, 0);
   AL10.alListener3f(AL10.AL_DIRECTION, directionX, directionY, directionZ);
}

Audio source init/creation:
buffer = AudioMaster.loadSound("StartBlurMusicMono");
for (int i = 0; i < 8; i++)
{
   list.add(new Source(buffer));
   currentSource = list.get(list.size() - 1);
   currentSource.setLooping(true);
   currentSource.setPosition(100 + i * 100, 50, -100);
   currentSource.setRefferenceDistance(105);
   currentSource.setMaxDistance(200);
   currentSource.setRollOffFactor(10f);
   currentSource.setVolume(0.6f);
   currentSource.play();
   currentSource.pause();
   currentSource.setDirection(1f, 0f, 0f);
}

 98 
 on: February 06, 2017, 07:48:41 
Started by KKSystem - Last post by Kai
http://forum.lwjgl.org/index.php?topic=6080.0

 99 
 on: February 06, 2017, 03:12:03 
Started by KKSystem - Last post by KKSystem
Hi everybody,
I am using OpanGL in lwjgl according to karl (ThinMatrix) youtube tutorial, and I try this 3 weeks to find out how do I make the music to know in which direction my camera is on.
For example, when I looking with my camera forward the music needs to be in my right ear, and when I looking with my camera to back, the music needs to be in my left ear.
Do someone know how do I can do it?
Thanks for help,
Korel.

 100 
 on: February 05, 2017, 17:33:01 
Started by MasterAbdoTGM50 - Last post by MasterAbdoTGM50
So essentially it's only a question of whether I want the whole file buffered or do I wanna stream it

Thank you alot Spasi :D

Pages: 1 ... 8 9 [10]