SoundManager, SoundBuffer Fixed, BufferUtils.java rename to BufferUtilsEngine.java to avoid conflict with org.lwjgl.BufferUtils
Le son fonctionne yay
This commit is contained in:
parent
00a19177c7
commit
bd587a5587
@ -9,7 +9,6 @@ public class JsonToJava {
|
|||||||
JSONParser jsonP = new JSONParser();
|
JSONParser jsonP = new JSONParser();
|
||||||
try {
|
try {
|
||||||
JSONObject jsonO = (JSONObject)jsonP.parse(new FileReader("src/configuration/config.json"));
|
JSONObject jsonO = (JSONObject)jsonP.parse(new FileReader("src/configuration/config.json"));
|
||||||
|
|
||||||
String test = (String) jsonO.get("test");
|
String test = (String) jsonO.get("test");
|
||||||
System.out.println("Name :"+ test);
|
System.out.println("Name :"+ test);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package engine;
|
package engine;
|
||||||
|
|
||||||
import engine.input.Input;
|
import engine.input.Input;
|
||||||
|
//import engine.input.gamepadInput;
|
||||||
import engine.input.gamepadInput;
|
import engine.input.gamepadInput;
|
||||||
import engine.math.*;
|
import engine.math.*;
|
||||||
import engine.object.*;
|
import engine.object.*;
|
||||||
@ -173,12 +174,12 @@ public class Engine {
|
|||||||
|
|
||||||
soundManager.setListener(soundListener);
|
soundManager.setListener(soundListener);
|
||||||
|
|
||||||
// SoundBuffer jumpSoundBuffer = new SoundBuffer("sound/jump.ogg"); EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ff893802818, pid=1788, tid=4548
|
SoundBuffer jumpSoundBuffer = new SoundBuffer("sound/jump.ogg");
|
||||||
// SoundSource soundSource = new SoundSource(true, false);
|
SoundSource soundSource = new SoundSource(true, false);
|
||||||
// soundSource.setBuffer(jumpSoundBuffer.getBufferId());
|
soundSource.setBuffer(jumpSoundBuffer.getBufferId());
|
||||||
//
|
|
||||||
// soundManager.addSoundSource("jump", soundSource);
|
soundManager.addSoundSource("jump", soundSource);
|
||||||
// soundManager.playSoundSource("jump");
|
soundManager.playSoundSource("jump");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Engine Init
|
Engine Init
|
||||||
@ -217,7 +218,7 @@ public class Engine {
|
|||||||
// Game logic should fit here
|
// Game logic should fit here
|
||||||
|
|
||||||
if (present) { //sprite //bindings
|
if (present) { //sprite //bindings
|
||||||
gamepadInput.gamepadInput(zangief, speed, buttonA, buttonB, buttonX, buttonY);
|
gamepadInput.gamepadInput(zangief, speed, buttonA, buttonB, buttonX, buttonY);
|
||||||
|
|
||||||
System.out.println( " \n A :" + gamepadInput.buttonA_pressed +
|
System.out.println( " \n A :" + gamepadInput.buttonA_pressed +
|
||||||
" \n B :" + gamepadInput.buttonB_pressed +
|
" \n B :" + gamepadInput.buttonB_pressed +
|
||||||
@ -225,7 +226,7 @@ public class Engine {
|
|||||||
" \n X :" + gamepadInput.buttonX_pressed);
|
" \n X :" + gamepadInput.buttonX_pressed);
|
||||||
}
|
}
|
||||||
|
|
||||||
Input.keyboardInput(zangief, speed);
|
// Input.keyboardInput(zangief, speed);
|
||||||
// input(smiley2, speed);
|
// input(smiley2, speed);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package engine.graphics;
|
package engine.graphics;
|
||||||
|
|
||||||
import engine.utils.BufferUtils;
|
import engine.utils.BufferUtilsEngine;
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
@ -49,7 +49,7 @@ public class Texture {
|
|||||||
glBindTexture(GL_TEXTURE_2D, result);
|
glBindTexture(GL_TEXTURE_2D, result);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
GL11.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, BufferUtils.createIntBuffer(data));
|
GL11.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, BufferUtilsEngine.createIntBuffer(data));
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
return result;
|
return result;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package engine.graphics;
|
package engine.graphics;
|
||||||
|
|
||||||
import engine.utils.BufferUtils;
|
import engine.utils.BufferUtilsEngine;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
import static org.lwjgl.opengl.GL15.*;
|
import static org.lwjgl.opengl.GL15.*;
|
||||||
@ -28,7 +28,7 @@ public class VertexArray {
|
|||||||
|
|
||||||
EBO = glGenBuffers();
|
EBO = glGenBuffers();
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, BufferUtils.createByteBuffer(indices), GL_STATIC_DRAW);
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, BufferUtilsEngine.createByteBuffer(indices), GL_STATIC_DRAW);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ public class VertexArray {
|
|||||||
private void createVertexBufferObject(float[] vertices){
|
private void createVertexBufferObject(float[] vertices){
|
||||||
VBO = glGenBuffers();
|
VBO = glGenBuffers();
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
glBufferData(GL_ARRAY_BUFFER, BufferUtils.createFloatBuffer(vertices), GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, BufferUtilsEngine.createFloatBuffer(vertices), GL_STATIC_DRAW);
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
|
glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
}
|
}
|
||||||
@ -45,7 +45,7 @@ public class VertexArray {
|
|||||||
private void createColorBufferObject(float[] color){
|
private void createColorBufferObject(float[] color){
|
||||||
CBO = glGenBuffers();
|
CBO = glGenBuffers();
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, CBO);
|
glBindBuffer(GL_ARRAY_BUFFER, CBO);
|
||||||
glBufferData(GL_ARRAY_BUFFER, BufferUtils.createFloatBuffer(color), GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, BufferUtilsEngine.createFloatBuffer(color), GL_STATIC_DRAW);
|
||||||
glVertexAttribPointer(1, 3, GL_FLOAT, false, 0, 0);
|
glVertexAttribPointer(1, 3, GL_FLOAT, false, 0, 0);
|
||||||
glEnableVertexAttribArray(1);
|
glEnableVertexAttribArray(1);
|
||||||
}
|
}
|
||||||
@ -53,19 +53,19 @@ public class VertexArray {
|
|||||||
private void createTextureBufferObject(float[] texture){
|
private void createTextureBufferObject(float[] texture){
|
||||||
TBO = glGenBuffers();
|
TBO = glGenBuffers();
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, TBO);
|
glBindBuffer(GL_ARRAY_BUFFER, TBO);
|
||||||
glBufferData(GL_ARRAY_BUFFER, BufferUtils.createFloatBuffer(texture), GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, BufferUtilsEngine.createFloatBuffer(texture), GL_STATIC_DRAW);
|
||||||
glVertexAttribPointer(2, 2, GL_FLOAT, false, 0, 0);
|
glVertexAttribPointer(2, 2, GL_FLOAT, false, 0, 0);
|
||||||
glEnableVertexAttribArray(2);
|
glEnableVertexAttribArray(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void swapVertexBufferObject(float[] vertices){
|
public void swapVertexBufferObject(float[] vertices){
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
glBufferData(GL_ARRAY_BUFFER, BufferUtils.createFloatBuffer(vertices), GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, BufferUtilsEngine.createFloatBuffer(vertices), GL_STATIC_DRAW);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void swapTextureBufferObject(float [] texture){
|
public void swapTextureBufferObject(float [] texture){
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, TBO);
|
glBindBuffer(GL_ARRAY_BUFFER, TBO);
|
||||||
glBufferData(GL_ARRAY_BUFFER, BufferUtils.createFloatBuffer(texture), GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, BufferUtilsEngine.createFloatBuffer(texture), GL_STATIC_DRAW);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bind(){
|
public void bind(){
|
||||||
|
@ -15,7 +15,6 @@ import static org.lwjgl.opengl.GL11.*;
|
|||||||
public class Input extends GLFWKeyCallback {
|
public class Input extends GLFWKeyCallback {
|
||||||
|
|
||||||
public static boolean[] keys = new boolean[65536];
|
public static boolean[] keys = new boolean[65536];
|
||||||
public static boolean keyPressed = false;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(long window, int key, int scancode, int action, int mods) {
|
public void invoke(long window, int key, int scancode, int action, int mods) {
|
||||||
@ -38,6 +37,9 @@ public class Input extends GLFWKeyCallback {
|
|||||||
assert gamepadAxes != null;
|
assert gamepadAxes != null;
|
||||||
assert gamepadButton != null;
|
assert gamepadButton != null;
|
||||||
|
|
||||||
|
String name = GLFW.glfwGetJoystickName(GLFW_JOYSTICK_1);
|
||||||
|
System.out.println("GamePad Name :" + name);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (gamepadButton.get(0) ==1 ) { // appuie sur croix(PlayStation) A (Xbox)
|
if (gamepadButton.get(0) ==1 ) { // appuie sur croix(PlayStation) A (Xbox)
|
||||||
@ -46,9 +48,9 @@ public class Input extends GLFWKeyCallback {
|
|||||||
if ( (gamepadAxes.get(2) < -0.1 || gamepadAxes.get(2) > 0.1) ) { // de droite à gauche //joystick gauche
|
if ( (gamepadAxes.get(2) < -0.1 || gamepadAxes.get(2) > 0.1) ) { // de droite à gauche //joystick gauche
|
||||||
token.translate(new Vector3f (5 * speed * gamepadAxes.get(2), 0.0f, 0.0f));
|
token.translate(new Vector3f (5 * speed * gamepadAxes.get(2), 0.0f, 0.0f));
|
||||||
if ( gamepadAxes.get(2) < -0.1 ){
|
if ( gamepadAxes.get(2) < -0.1 ){
|
||||||
token.setTextureWrap(121,0,57,80, ObjectGl.STICK_TOP);
|
token.setTextureWrap(121,0,57,80, ObjectGl.DEFAULT);
|
||||||
}else if (gamepadAxes.get(2) > 0.1) {
|
}else if (gamepadAxes.get(2) > 0.1) {
|
||||||
token.setTextureWrap(178,0,62,82, ObjectGl.STICK_TOP);
|
token.setTextureWrap(178,0,62,82, ObjectGl.DEFAULT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +88,7 @@ public class Input extends GLFWKeyCallback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void keyboardInput(ObjectGl token, int speed) {
|
public static void keyboardInput(ObjectGl token, int speed) {
|
||||||
|
boolean keyPressed = false;
|
||||||
if (Input.isKeyDown(GLFW.GLFW_KEY_S)) {
|
if (Input.isKeyDown(GLFW.GLFW_KEY_S)) {
|
||||||
token.setTextureWrap(161,260,56,59, ObjectGl.STICK_BOTTOM);
|
token.setTextureWrap(161,260,56,59, ObjectGl.STICK_BOTTOM);
|
||||||
keyPressed = true;
|
keyPressed = true;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package engine.math;
|
package engine.math;
|
||||||
|
|
||||||
import engine.utils.BufferUtils;
|
import engine.utils.BufferUtilsEngine;
|
||||||
|
|
||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ public class Matrix4f {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public FloatBuffer toFloatBuffer() {
|
public FloatBuffer toFloatBuffer() {
|
||||||
return BufferUtils.createFloatBuffer(elements);
|
return BufferUtilsEngine.createFloatBuffer(elements);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package engine.sound;
|
package engine.sound;
|
||||||
|
|
||||||
|
import engine.utils.FileUtils;
|
||||||
import org.lwjgl.stb.STBVorbisInfo;
|
import org.lwjgl.stb.STBVorbisInfo;
|
||||||
import org.lwjgl.system.MemoryStack;
|
import org.lwjgl.system.MemoryStack;
|
||||||
import org.lwjgl.system.MemoryUtil;
|
import org.lwjgl.system.MemoryUtil;
|
||||||
@ -13,7 +14,6 @@ import java.nio.ByteBuffer;
|
|||||||
import java.nio.IntBuffer;
|
import java.nio.IntBuffer;
|
||||||
import java.nio.ShortBuffer;
|
import java.nio.ShortBuffer;
|
||||||
|
|
||||||
import static engine.utils.BufferUtils.StringToByteBuffer;
|
|
||||||
import static org.lwjgl.openal.AL10.*;
|
import static org.lwjgl.openal.AL10.*;
|
||||||
import static org.lwjgl.stb.STBVorbis.*;
|
import static org.lwjgl.stb.STBVorbis.*;
|
||||||
import static org.lwjgl.system.MemoryUtil.NULL;
|
import static org.lwjgl.system.MemoryUtil.NULL;
|
||||||
@ -56,19 +56,19 @@ public class SoundBuffer {
|
|||||||
/**
|
/**
|
||||||
* Source : https://github.com/lwjglgamedev/lwjglbook/blob/master/chapter28/src/main/java/org/lwjglb/engine/sound/SoundBuffer.java
|
* Source : https://github.com/lwjglgamedev/lwjglbook/blob/master/chapter28/src/main/java/org/lwjglb/engine/sound/SoundBuffer.java
|
||||||
* lis un fichier .ogg et le convertis en .pcm seul format lisible par openAl
|
* lis un fichier .ogg et le convertis en .pcm seul format lisible par openAl
|
||||||
* @param resource le fichier .ogg
|
* @param path chemin vers un fichier .ogg
|
||||||
* @param info STBVorbisInfo
|
* @param info STBVorbisInfo
|
||||||
* @return pcm
|
* @return pcm
|
||||||
* @throws Exception MemoryStack.stackPush()
|
* @throws Exception MemoryStack.stackPush()
|
||||||
*/
|
*/
|
||||||
private ShortBuffer readVorbis(String resource, STBVorbisInfo info) throws Exception {
|
private ShortBuffer readVorbis(String path, STBVorbisInfo info) throws Exception {
|
||||||
try (MemoryStack stack = MemoryStack.stackPush()) {
|
try (MemoryStack stack = MemoryStack.stackPush()) {
|
||||||
vorbis = StringToByteBuffer(resource);
|
this.vorbis = FileUtils.loadAsByteBuffer(path);
|
||||||
IntBuffer error = stack.mallocInt(1);
|
IntBuffer error = stack.mallocInt(1);
|
||||||
long decoder = stb_vorbis_open_memory(vorbis, error, null);
|
long decoder = stb_vorbis_open_memory(vorbis, error, null);
|
||||||
if (decoder == NULL) {
|
if (decoder == NULL) {
|
||||||
throw new RuntimeException("Failed to open Ogg Vorbis file. Error: " + error.get(0));
|
throw new RuntimeException("Failed to open Ogg Vorbis file. Error: " + error.get(0));
|
||||||
}
|
} //Failed to open Ogg Vorbis file. Error: 30 / 34
|
||||||
|
|
||||||
stb_vorbis_get_info(decoder, info);
|
stb_vorbis_get_info(decoder, info);
|
||||||
|
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
package engine.utils;
|
package engine.utils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.RandomAccessFile;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
import java.nio.IntBuffer;
|
import java.nio.IntBuffer;
|
||||||
|
import java.nio.channels.FileChannel;
|
||||||
|
|
||||||
public class BufferUtils {
|
public class BufferUtilsEngine {
|
||||||
|
|
||||||
private BufferUtils() {
|
private BufferUtilsEngine() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,8 +32,4 @@ public class BufferUtils {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ByteBuffer StringToByteBuffer(String msg){
|
|
||||||
return ByteBuffer.wrap(msg.getBytes());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -1,9 +1,13 @@
|
|||||||
package engine.utils;
|
package engine.utils;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import org.lwjgl.BufferUtils;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileReader;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.channels.SeekableByteChannel;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
public class FileUtils {
|
public class FileUtils {
|
||||||
|
|
||||||
@ -17,13 +21,27 @@ public class FileUtils {
|
|||||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||||
String buffer = "";
|
String buffer = "";
|
||||||
while ((buffer = reader.readLine()) != null) {
|
while ((buffer = reader.readLine()) != null) {
|
||||||
result.append(buffer +"\n");
|
result.append(buffer).append("\n");
|
||||||
}
|
}
|
||||||
reader.close();
|
reader.close();
|
||||||
} catch (IOException e){
|
} catch (IOException e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
System.exit(1);
|
||||||
}
|
}
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ByteBuffer loadAsByteBuffer(String file) throws IOException{
|
||||||
|
ByteBuffer buffer;
|
||||||
|
|
||||||
|
Path path = Paths.get(file);
|
||||||
|
|
||||||
|
try (SeekableByteChannel fc = Files.newByteChannel(path)) {
|
||||||
|
buffer = BufferUtils.createByteBuffer((int) fc.size() + 1);
|
||||||
|
while (fc.read(buffer) != -1) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer.flip();
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user