Hello Guest

Recent Posts

Pages: 1 ... 8 9 [10]
91
OpenAL / Re: Strange NullPointerException with Loading Audio....
« Last post by spasi on June 13, 2018, 19:15:15 »
You can either use an absolute path, or a path relative to the working directory of the process. In any other case, use Java (N)IO to load the file to a buffer and use stb_vorbis_decode_memory instead.

Anyway, in this case the problem seems to be that you're trying to decode a .wav file as an Ogg Vorbis file. That's not going to work.
92
OpenAL / Re: Strange NullPointerException with Loading Audio....
« Last post by DGK on June 13, 2018, 19:10:29 »
The NPE happens because stb_vorbis_decode_filename has returned null. It means it couldn't find the file or decoding failed somehow (corrupt vorbis file?).

I figured that but the fileName is right, but I have my .wav file in res/sounds/buttonClick.wav. I tried moving it into the first folder for the project and it still won't load it. It is kind of ambiguous where it loads the file from, do you know how to fix that?
93
OpenAL / Re: Strange NullPointerException with Loading Audio....
« Last post by spasi on June 13, 2018, 15:56:57 »
The NPE happens because stb_vorbis_decode_filename has returned null. It means it couldn't find the file or decoding failed somehow (corrupt vorbis file?).
94
Bug Reports / RFE / Re: Issue with tinyexr loading
« Last post by spasi on June 13, 2018, 15:39:35 »
Reproduced with 3.1.6. It doesn't happen with 3.1.7. The EXRHeader validation NPE will be fixed in the next 3.1.7 snapshot.
95
Bug Reports / RFE / Re: Issue with tinyexr loading
« Last post by xsupermetroidx on June 13, 2018, 10:58:14 »
Windows 7 64 bit, current release build (3.1.6 build 14), Java 10.0.1.

I just tried updating LWJGL to the latest "stable" build (3.1.7) and I'm getting a new error which is occuring at the SaveEXRImageToFile call in the demo code:

Code: [Select]
Exception in thread "main" java.lang.NullPointerException
at org.lwjgl.system.Checks.check(Checks.java:100)
at org.lwjgl.util.tinyexr.EXRHeader.validate(EXRHeader.java:622)
at org.lwjgl.util.tinyexr.TinyEXR.SaveEXRImageToFile(TinyEXR.java:411)
at glimdemo.main.EXRTest.save(EXRTest.java:130)
at glimdemo.main.EXRTest.tinyEXRTest(EXRTest.java:32)
at glimdemo.main.Main.main(Main.java:289)

Seems to be having an issue with the custom attributes of the exr_header.
96
Bug Reports / RFE / Re: Issue with tinyexr loading
« Last post by spasi on June 13, 2018, 10:15:21 »
Still cannot reproduce this, the output is fine, without any random numbers. Could you share some details about your environment? (OS, LWJGL version, JVM version)
97
Bug Reports / RFE / Re: Issue with tinyexr loading
« Last post by xsupermetroidx on June 13, 2018, 08:26:07 »
I'm sure that they are saved and loaded as TINYEXR_PIXELTYPE_FLOAT. When I load a demo EXR file off the internet, it works fine. When I save and reload that same image, the corruption in the final row of pixels shows up. However, the re-saved image still shows up fine in EXR viewers. Perhaps the EXR viewers I tried are more tolerant of faulty files, or perhaps there's an issue with my save/load code, although it's copied as nearly as I can manage from tinyEXR's docs. I've assembled a self-sufficient test case for you to take a look at when you have time.

Code: [Select]
import org.lwjgl.BufferUtils;
import org.lwjgl.PointerBuffer;
import org.lwjgl.util.tinyexr.*;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;

import static org.lwjgl.util.tinyexr.TinyEXR.*;

public class EXRTest {

    public static void tinyEXRTest() {
        String path = ""; //insert file path here

        //create a simple raster
        float[] raster = new float[] {
            1f, 2f, 3f, 4f,    1f, 2f, 3f, 4f,    1f, 2f, 3f, 4f,
            1f, 2f, 3f, 4f,    1f, 2f, 3f, 4f,    1f, 2f, 3f, 4f,
            1f, 2f, 3f, 4f,    1f, 2f, 3f, 4f,    1f, 2f, 3f, 4f,
        };
        //save EXR to disk: no errors, looks fine in EXR viewer program
        save(pathExr, 3, 3, raster);

        //load EXR and get FloatBuffers for each channel
        FloatBuffer[] fbs = load(pathExr);

        for (int i = 0; i < 3*3; i++) {
            System.out.print(fbs[0].get(i) + ", ");
            System.out.print(fbs[1].get(i) + ", ");
            System.out.print(fbs[2].get(i) + ", ");
            System.out.println(fbs[3].get(i));
        }

//        Output:
//        1.0, 2.0, 3.0, 4.0
//        1.0, 2.0, 3.0, 4.0
//        1.0, 2.0, 3.0, 4.0
//        1.0, 2.0, 3.0, 4.0
//        1.0, 2.0, 3.0, 4.0
//        1.0, 2.0, 3.0, 4.0
//        133169.11, 4.611403E27, 2.626384E32, 1.172696E-39
//        1.18026E-40, 2.070413E-19, 2.4149792E8, 3.0353178E-31
//        1.1429877E33, 7.715514E31, 4.7423467E30, 8538626.0
    }

    private static ByteBuffer strBB(String s) {
        byte[] bytes = s.getBytes();
        ByteBuffer bb = BufferUtils.createByteBuffer(bytes.length);
        bb.put(bytes);
        bb.flip();
        return bb;
    }

    private static void save(String path, int width, int height, float[] rgba) {
        EXRHeader exr_header = EXRHeader.create();
        InitEXRHeader(exr_header);

        EXRImage exr_image = EXRImage.create();
        InitEXRImage(exr_image);

        exr_image.num_channels(4);
        exr_header.num_channels(4);

        float[][] images = new float[4][width * height];

        int x = 0;
        int y = 0;
        for (int i = 0; i < width * height; i++) {
            images[0][i] = rgba[4*i+0];
            images[1][i] = rgba[4*i+1];
            images[2][i] = rgba[4*i+2];
            images[3][i] = rgba[4*i+3];
        }

        FloatBuffer red = BufferUtils.createFloatBuffer(width * height);
        red.put(images[0]);
        red.flip();
        FloatBuffer green = BufferUtils.createFloatBuffer(width * height);
        green.put(images[1]);
        green.flip();
        FloatBuffer blue = BufferUtils.createFloatBuffer(width * height);
        blue.put(images[2]);
        blue.flip();
        FloatBuffer alpha = BufferUtils.createFloatBuffer(width * height);
        alpha.put(images[3]);
        alpha.flip();

        PointerBuffer imagesPtr = BufferUtils.createPointerBuffer(4);
        imagesPtr.put(red);
        imagesPtr.put(green);
        imagesPtr.put(blue);
        imagesPtr.put(alpha);
        imagesPtr.flip();

        exr_image.images(imagesPtr);
        exr_image.width(width);
        exr_image.height(height);

        EXRChannelInfo.Buffer channelInfos = EXRChannelInfo.create(exr_header.num_channels());
        exr_header.channels(channelInfos);
        channelInfos.get(0).name(strBB("R\0"));
        channelInfos.get(1).name(strBB("G\0"));
        channelInfos.get(2).name(strBB("B\0"));
        channelInfos.get(3).name(strBB("A\0"));

        IntBuffer pixelTypes = BufferUtils.createIntBuffer(exr_header.num_channels());
        IntBuffer requestedPixelTypes = BufferUtils.createIntBuffer(exr_header.num_channels());
        exr_header.pixel_types(pixelTypes);
        exr_header.requested_pixel_types(requestedPixelTypes);
        for (int i = 0; i < exr_header.num_channels(); i++) {
            pixelTypes.put(i, TINYEXR_PIXELTYPE_FLOAT);
            requestedPixelTypes.put(i, TINYEXR_PIXELTYPE_FLOAT);
        }

        PointerBuffer err = BufferUtils.createPointerBuffer(1);
        int ret = SaveEXRImageToFile(exr_image, exr_header, path, err);
        if (ret != TINYEXR_SUCCESS) {
            System.out.println("EXR err: " + err.get(0));
        }
        System.out.println("EXR saved at " + path);
    }

    private static FloatBuffer[] load(String path) {
        EXRVersion exr_version = EXRVersion.create();

        int ret = ParseEXRVersionFromFile(exr_version, path);
        if (ret != TINYEXR_SUCCESS) {
            System.out.println("Invalid EXR file: " + path);
            return null;
        }

        if (exr_version.multipart()) {
            System.out.println("Multipart unsupported");
            return null;
        }

        EXRHeader exr_header = EXRHeader.create();
        InitEXRHeader(exr_header);

        PointerBuffer err = BufferUtils.createPointerBuffer(1);
        ret = ParseEXRHeaderFromFile(exr_header, exr_version, path, err);
        if (ret != TINYEXR_SUCCESS) {
            System.out.println("EXR parse error: " + err.get(0));
            return null;
        }

        // Read HALF channel as FLOAT.
        for (int i = 0; i < exr_header.num_channels(); i++) {
            if (exr_header.pixel_types().get(i) == TINYEXR_PIXELTYPE_HALF) {
                exr_header.requested_pixel_types().put(i, TINYEXR_PIXELTYPE_FLOAT);
            }
        }

        EXRImage exr_image = EXRImage.create();
        InitEXRImage(exr_image);

        ret = LoadEXRImageFromFile(exr_image, exr_header, path, err);
        if (ret != TINYEXR_SUCCESS) {
            System.out.println("EXR load errror: " + err.get(0));
            return null;
        }

        PointerBuffer images = exr_image.images();
        int w = exr_image.width();
        int h = exr_image.height();

        return new FloatBuffer[] {
            images.getFloatBuffer(0, w * h),
            images.getFloatBuffer(1, w * h),
            images.getFloatBuffer(2, w * h),
            images.getFloatBuffer(3, w * h)
        };
    }

}
98
OpenAL / Strange NullPointerException with Loading Audio....
« Last post by DGK on June 13, 2018, 03:11:19 »
I am getting a NullPointerException trying to load audio with OpenAL. I am using LWJGL 3, and I have no idea how to fix it. Searched everywhere.

Error below:

Code: [Select]
Exception in thread "main" java.lang.NullPointerException
at org.lwjgl.system.MemoryUtil.memAddress(MemoryUtil.java:653)
at org.lwjgl.openal.AL10.alBufferData(AL10.java:1436)
at dgk.prototype.sound.Sound.<init>(Sound.java:46)
at dgk.prototype.sound.SoundManager.start(SoundManager.java:41)
at dgk.prototype.game.GameWindow.loop(GameWindow.java:169)
at dgk.prototype.main.Main.main(Main.java:12)
AL lib: (EE) alc_cleanup: 1 device not closed

Classes used:

Code: [Select]
package dgk.prototype.sound;

import dgk.prototype.util.IManager;
import org.lwjgl.openal.AL;
import org.lwjgl.openal.ALC;
import org.lwjgl.openal.ALCCapabilities;
import org.lwjgl.openal.ALCapabilities;

import java.util.HashMap;

import static org.lwjgl.openal.ALC10.*;

public class SoundManager implements IManager {

    private HashMap<String, Sound> soundMap;

    private long device;
    private long context;

    public SoundManager() {
        this.soundMap = new HashMap<String, Sound>();
    }

    @Override
    public void start() {
        String defaultDevice = alcGetString(0, ALC_DEFAULT_DEVICE_SPECIFIER);
        device = alcOpenDevice(defaultDevice);

        int[] attr = {0};

        context = alcCreateContext(device, attr);
        alcMakeContextCurrent(context);

        ALCCapabilities alcCapabilities = ALC.createCapabilities(device);
        ALCapabilities alCapabilities = AL.createCapabilities(alcCapabilities);

        if(alCapabilities.OpenAL10) {
            System.out.println("OpenAL 1.0 is supported.");
        }

        Sound sound = new Sound("buttonClick.wav");

        soundMap.put("buttonClick", sound);
    }

    public Sound getSound(String name) {
        if(soundMap.containsKey(name)) {
            return soundMap.get(name);
        }

        return null;
    }

    public boolean hasSound(String name) {
        return (soundMap.containsKey(name));
    }

    @Override
    public void stop() {
        alcDestroyContext(context);
        alcCloseDevice(device);
    }

    @Override
    public void onUpdate() {

    }
}

Code: [Select]
package dgk.prototype.sound;

import java.nio.IntBuffer;
import java.nio.ShortBuffer;

import static org.lwjgl.openal.AL10.*;
import static org.lwjgl.stb.STBVorbis.stb_vorbis_decode_filename;
import static org.lwjgl.system.MemoryStack.stackMallocInt;
import static org.lwjgl.system.MemoryStack.stackPop;
import static org.lwjgl.system.MemoryStack.stackPush;
import static org.lwjgl.system.libc.LibCStdlib.free;

public class Sound {

    private int bufferPointer;
    private int sourcePointer;

    public Sound(String fileName) {
        //File file = new File("res/sounds/" + fileName + ".wav");

        stackPush();

        IntBuffer channelBuffer = stackMallocInt(1);
        stackPush();
        IntBuffer sampleRateBuffer = stackMallocInt(1);

        ShortBuffer audioBuffer = stb_vorbis_decode_filename(fileName, channelBuffer, sampleRateBuffer);


        int channels = channelBuffer.get();
        int sampleRate = sampleRateBuffer.get();

        stackPop();
        stackPop();

        int format = -1;

        if(channels == 1) {
            format = AL_FORMAT_MONO16;
        }else if(channels == 2) {
            format = AL_FORMAT_STEREO16;
        }

        bufferPointer = alGenBuffers();

        alBufferData(bufferPointer, format, audioBuffer, sampleRate);

        //free(audioBuffer);

        sourcePointer = alGenSources();
    }

    public int getSourcePointer() {
        return sourcePointer;
    }

    public void playSound() {
        alSourcei(sourcePointer, AL_BUFFER, bufferPointer);

        alSourcePlay(sourcePointer);
    }

    public void destroy() {
        alDeleteBuffers(bufferPointer);
        alDeleteSources(sourcePointer);
    }
}
99
OpenGL / Re: Use opengl commands without the opengl version
« Last post by spasi on June 12, 2018, 20:18:53 »
And generally speaking, is it a bad practice using it that way? Or its fine? Thanks.

All LWJGL bindings are designed to be used with static imports. It's perfectly fine.

There are some exceptions with OpenGL though. Normally extensions are introduced with ARB/EXT/etc suffixes and the suffixes are dropped when an extension is promoted to core. So normally there are no conflicts. In later OpenGL versions, the extension and core functionality were introduced at the same time, both without suffixes. Importing both will cause conflicts, but (if you ever need to do that) it's easy to workaround/isolate with the right abstractions.
100
OpenGL / Re: Use opengl commands without the opengl version
« Last post by msacco on June 12, 2018, 20:16:34 »
And generally speaking, is it a bad practice using it that way? Or its fine? Thanks.
It's generally fine.

Awesome, thanks!
Pages: 1 ... 8 9 [10]