finish openal and ALUT

This commit is contained in:
Tyler Murphy 2022-09-22 13:21:30 -04:00
parent 5d07a3c101
commit 8d9c74bc4f
7 changed files with 11 additions and 106 deletions

View file

@ -12,7 +12,7 @@ CCFLAGS += $(INCFLAGS)
LDFLAGS = -lm
LDFLAGS += $(INCFLAGS)
LDFLAGS += lib/glfw/src/libglfw3.a
LDFLAGS += -lglfw
LDFLAGS += lib/glm/glm/libglm_static.a
LDFLAGS += -lopenal
LDFLAGS += -lalut

View file

@ -1,6 +1,8 @@
#include "xe_engine.hpp"
#include "xe_image.hpp"
#include <chrono>
#include <AL/alut.h>
namespace xe {
@ -9,6 +11,11 @@ XeEngine::XeEngine(int width, int height, std::string name) : xeWindow{width, he
xeRenderer{xeWindow, xeDevice},
xeCamera{} {
loadDescriptorPool();
alutInit(0, NULL);
};
XeEngine::~XeEngine() {
alutExit();
};
void XeEngine::loadDescriptorPool() {

View file

@ -6,7 +6,6 @@
#include "xe_camera.hpp"
#include "xe_descriptors.hpp"
#include "xe_image.hpp"
#include "xe_sound_device.hpp"
#include <chrono>
#include <string>
@ -18,7 +17,7 @@ class XeEngine {
XeEngine(int width, int height, std::string name);
~XeEngine() {};
~XeEngine();
XeEngine(const XeEngine&) = delete;
XeEngine operator=(const XeEngine&) = delete;
@ -45,7 +44,6 @@ class XeEngine {
XeDevice xeDevice;
XeRenderer xeRenderer;
XeCamera xeCamera;
XeSoundDevice xeSoundDevice;
std::chrono::_V2::system_clock::time_point currentTime;
float frameTime;

View file

@ -8,20 +8,8 @@ namespace xe {
XeSound::XeSound(const std::string& filename) {
// ALvoid *data;
// ALsizei size, freq;
// ALenum format;
// ALboolean loop;
// char *bufferData;
alutInit(0, NULL);
std::cout << std::hex << alutGetError() << "\n";
buffer = alutCreateBufferFromFile(filename.c_str());
std::cout << std::hex << alutGetError() << "\n";
alGenSources(1, &source);
alSourcef(source, AL_GAIN, 1.f);
@ -30,13 +18,13 @@ XeSound::XeSound(const std::string& filename) {
alSource3f(source, AL_VELOCITY, 0, 0, 0);
alSourcei(source, AL_LOOPING, AL_FALSE);
alSourcei(source, AL_BUFFER, buffer);
alSourcef(source, AL_GAIN, 3.f);
}
XeSound::~XeSound() {
alDeleteSources(1, &source);
alDeleteBuffers(1, &buffer);
alutExit();
}
void XeSound::play() {

View file

@ -1,64 +0,0 @@
#include "xe_sound_device.hpp"
#include <stdexcept>
#include <iostream>
#include <cstring>
namespace xe {
XeSoundDevice::XeSoundDevice() {
// ALboolean enumeration;
// enumeration = alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT");
// if (enumeration == AL_FALSE) {
// fprintf(stderr, "enumeration extension not available\n");
// listAudioDevices(alcGetString(NULL, ALC_DEVICE_SPECIFIER));
// }
// listAudioDevices(alcGetString(NULL, ALC_DEVICE_SPECIFIER));
// const ALCchar* name = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
// device = alcOpenDevice(name);
// if (!device) {
// std::runtime_error("failed to get sound device");
// }
// std::cout << "Audio Device: " << alcGetString(device, ALC_DEVICE_SPECIFIER) << "\n";
// context = alcCreateContext(device, NULL);
// if(!alcMakeContextCurrent(context)) {
// std::runtime_error("failed to make sound context current");
// }
// alListener3f(AL_POSITION, 0.f, 0.f, 0.f);
// alListener3f(AL_VELOCITY, 0.f, 0.f, 0.f);
// ALfloat frontAndUpVectors[] = {
// /* front*/1.f, 0.f, 0.f,
// /* up */ 0.f, 1.f, 0.f
// };
// alListenerfv(AL_ORIENTATION, frontAndUpVectors);
// }
// void XeSoundDevice::listAudioDevices(const ALCchar* devices) {
// const ALCchar *device = devices, *next = devices + 1;
// size_t len = 0;
// fprintf(stdout, "Devices list: ");
// while (device && *device != '\0' && next && *next != '\0') {
// fprintf(stdout, "%s, ", device);
// len = strlen(device);
// device += (len + 1);
// next += (len + 2);
// }
// std::cout << "\n";
}
XeSoundDevice::~XeSoundDevice() {
// alcMakeContextCurrent(nullptr);
// alcDestroyContext(context);
// alcCloseDevice(device);
}
}

View file

@ -1,25 +0,0 @@
#pragma once
#include <AL/alc.h>
#include <AL/alext.h>
#include <AL/al.h>
namespace xe {
class XeSoundDevice {
public:
XeSoundDevice();
~XeSoundDevice();
private:
void listAudioDevices(const ALCchar* devices);
ALCdevice* device;
ALCcontext* context;
};
}

1
lib/openal Submodule

@ -0,0 +1 @@
Subproject commit c52df6d78ab7131a543326cd2257f267036754e1