Please login or register.

Login with username, password and session length
Pages: 1 ... 8 9 [10]
 on: April 24, 2017, 13:08:42 
Started by dzolo - Last post by dzolo

I am trying to enable multisampling for a AWTGLCanvas that is places inside a Java Swing JFrame.

Until now I have no success to do so. I found an old thread that solved this within an Applet (http://forum.lwjgl.org/index.php?topic=1889.msg11119). But setting the PixelFormat as described in that post has no effect.

Do you please have any other tips to get the multisampling working?


Update: Added code sample.

Code: [Select]
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.gluOrtho2D;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.AWTGLCanvas;
import org.lwjgl.opengl.PixelFormat;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class CanvasTest {

  public static class CustomAWTGLCanvas extends AWTGLCanvas {

    public CustomAWTGLCanvas() throws LWJGLException {
      super(new PixelFormat(8, 8, 0, 4));

    public void paintGL() {
      try {
        glViewport(0, 0, getWidth(), getHeight());
        glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
        gluOrtho2D(0.0f, (float) getWidth(), 0.0f, (float) getHeight());
        glColor3f(1f, 1f, 0f);
        glTranslatef(getWidth() / 2.0f, getHeight() / 2.0f, 0.0f);
        glRotatef(51f, 0f, 0f, 1.0f);
        glRectf(-50.0f, -50.0f, 50.0f, 50.0f);
      } catch (LWJGLException ex) {

  public static void main(String[] args) throws LWJGLException {

    CustomAWTGLCanvas canvas = new CustomAWTGLCanvas();

    JPanel panel = new JPanel(new BorderLayout());
    panel.setMinimumSize(new Dimension(100, 100));

    JFrame frame = new JFrame("AWTGLCanvas - multisampling");
    frame.setPreferredSize(new Dimension(640, 480));


 on: April 24, 2017, 12:09:50 
Started by Spytrycer - Last post by Kai
Okay, if you want a "third-person camera" which always follows the player by keeping a fixed distance to the player and always has the same position relative to the player, then do the following:
1. build the view matrix V as usual (like shown in the FreeCamera/FreeCameraDemo)
2. for rendering the player, you need to have: V x V^-1 x T = T
     - V is the camera matrix built in step 1
     - V^-1 is the inverse of V (can compute with Matrix4f.invert())
     - T is the translation that positions the camera relative to the player
     - 'L x R' means: multiplying 'L' by 'R' (for example via Matrix4f.mul())
3. for rendering everything else, you need to have: T x V x M
     - T is the same T as above (the position of the camera relative to the player)
     - V again is the camera matrix built in step 1
     - M is the respective object's model transformation

At this point, you need to have a more thorough understanding of coordinate systems and linear algebra (i.e. for transformation matrices).
If you like to start with the basics, you can have a look at Khan's Academy Course "Linear Algebra" (beware: it'll teach you really fundamental and essential stuff which is not focused on computer graphics alone, and is also university-grade, which can be hard to follow at times).
Other good resources are:
- http://www.songho.ca/opengl/gl_transform.html
- https://processing.org/tutorials/transform2d/ (even if it is for 2D, it can be generalized to 3D)
- http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/

 on: April 24, 2017, 03:53:50 
Started by Spytrycer - Last post by Spytrycer
Ok, thats great help, I implemented the Code for the Positioning and it works perfectly!

And i dont think i want an Arcball Camera, im sorry, i might have spoken too wierd :)

What i want the Camera to do is to follow around the Player in every Movement.
The Player moves like a FreeCamera and the Camera follows behind.
What i dont want is to just move the Camera in the Function i call the Playermovement, i want the camera to move BASED on the players position and Rotation.

And that works just fine, at least for the Rotation. Just the Translation doesnt want to work.

GIF of Movement Example

As you see in the Gif, its all working, but the Camera class is not moving.
Or to be precise, it is moving but its being reset everytime, which makes this wobbling and glitching kinda thing.

As i mentioned earlier, i tried a translation of just 1,1,1 and it was doing this glitching back and forth the whole time.

I dont know why it is not translating the Cameras position.
I checked the Values i give into the translation, i even checked if that changes the position i get with your method and the Position doesnt seem to change.

For Position.Z for example it just takes the Value of the Differential Change.
The System.out.print for position.z looks like this:
Code: [Select]

Looks pretty much just like
Code: [Select]
dt * player.linearVel.x
Here is my viewMatrix:

Code: [Select]
public void move(double delta)

float dt = (float)delta;

//linearVel.fma(dt, linearAcc);

    //angularVel.fma(dt, angularAcc);
this.angularVel.x = player.angularVel.x;
    this.angularVel.y = -player.angularVel.y;
    this.angularVel.z = player.angularVel.z;

this.Rotation.x += dt*angularVel.x;
    this.Rotation.y += dt*angularVel.y;
    this.Rotation.z += dt*angularVel.z;
    linearVel.x = dt * player.linearVel.x;
    linearVel.y = dt * player.linearVel.y;
    linearVel.z = dt * player.linearVel.z;

    .translateLocal(linearVel.x,linearVel.y, linearVel.z);

    viewMatrix.getTranslation(position); // <- store entity's position


And BTW, is there a way to do
Code: [Select]
With the Entities or cameras Rotation too?

 on: April 23, 2017, 19:42:28 
Started by bcbradle - Last post by bcbradle
Sweet thanks for all your help, vulkan in clojure is going to rock :)

 on: April 23, 2017, 19:37:04 
Started by bcbradle - Last post by spasi
Raw pointers are considered "unsafe" in LWJGL, so methods that accept them are prefixed with 'n'. The method you're looking for is MemoryUtil.nmemFree(long). Example:

Code: [Select]
PointerBuffer pp = ...;
for ( int i = 0; i < pp.remaining(); i++ ) {

I don't know how memory allocations are done on the native side in lwjgl

The MemoryUtil methods directly call the corresponding method of the native memory allocator. The only utility they have is that the memory allocator is configurable; you can try another implementation without changing your program. By default, if the bindings are available, jemalloc will be used as the memory allocator. Otherwise, the default system allocator is used. I would like to try rpmalloc soon, it'd be nice to have a third option if it's competitive. Btw, you also have the option of using one allocator via MemoryUtil and another by using the corresponding bindings directly (via org.lwjgl.system.libc.LibCStdlib and org.lwjgl.system.jemalloc.*).

 on: April 23, 2017, 19:18:23 
Started by bcbradle - Last post by bcbradle
Yes, only the pointer is necessary to free an allocation.

how would you do it then?

I mean i know how to free a PointerBuffer instance foo using foo.free(), but what about all the buffers the PointerBuffer instance foo contains?

foo.get() returns a long (presumably the address of the current buffer stored), but can you use that to free anything? I'm looking inside MemoryUtil but can't find anything that would allow me to free an arbitrary address.

I was thinking of maybe doing foo.getByteBuffer().free(), but there isn't any such method (only getByteBuffer(size)). I would have to know the size of the current buffer in bytes in order to free it this way.

It seems kind of odd though. I don't know how memory allocations are done on the native side in lwjgl, but the c function "free" doesn't require a size, only an address (assuming it was previously allocated with malloc, calloc or realloc). So I feel it would be strange if it weren't possible to free memory with just an address in lwjgl, and that is why I'm asking.

 on: April 23, 2017, 19:02:35 
Started by bcbradle - Last post by spasi
Yes, only the pointer is necessary to free an allocation.

 on: April 23, 2017, 16:08:44 
Started by bcbradle - Last post by bcbradle
Specifically, without knowing their lengths.

Basically I want to be able to free the pointer buffer and all the things pointed to by it given only the pointer buffer instance.

 on: April 23, 2017, 12:22:06 
Started by Spytrycer - Last post by Kai
You can separate the translation of your entity from its rotation and compose both together when building the final model transformation matrix. However, when you still want to move an entity along its own local "forward"/"right"/"up" axes, then you need to compute these vectors in world-space first.
Instead, an easier way is to keep everything like it is now, and compute the origin of the entity in world-space via:
Code: [Select]
Matrix4f model = ...; // <- the model transformation matrix of the entity
Vector3f position = new Vector3f(); // <- position will be stored in here
model.getTranslation(position); // <- store entity's position

It sounds that you want to have an "arcball" camera. Is that right?
If that is the case, then have a look at: https://github.com/JOML-CI/joml-camera/blob/master/src/org/joml/camera/ArcBallCamera.java

The important part of it is the order of transformations in the viewMatrix() method:

You can throw all that ArcRotor/ScalarMover stuff out, as it is merely used to "smoothen" the rotation and translation of the arcball camera over time.

 on: April 23, 2017, 06:20:22 
Started by bcbradle - Last post by spasi
The VkClearColorValue class does not decide anything. Like all struct classes, it's a wrapper over a pointer address + byte size. Because it's a union, the offset of all 3 members is zero and the byte size is 4 x 4 bytes (i.e. 16 bytes total, not 48).

How those bytes are interpreted is specified by Vulkan; it depends on the format of the image or attachment. The getters and setters with different types provide type-safety over the raw bytes. You can use those that match the format of the image or attachment that you need to clear to a specific color. Using value.float32(2, 3f) and value.int32(2, 3) will both write 4 bytes at offset 8 in the struct, but obviously different bytes will be written. There is no difference between int32 and uint32 in Java, but because of the properties of two's complement binary representation, you can use a Java int as a uint32_t.

Pages: 1 ... 8 9 [10]