Add openal-soft dependency, update opengl macro
This commit is contained in:
+3
-2
@@ -6,9 +6,10 @@
|
||||
#define STB_TRUETYPE_IMPLEMENTATION
|
||||
#include <STB/stb_truetype.h>
|
||||
|
||||
#include "Dengine/Platform.h"
|
||||
#include "Dengine/AssetManager.h"
|
||||
#include "Dengine/Debug.h"
|
||||
#include "Dengine/OpenGL.h"
|
||||
#include "Dengine/Platform.h"
|
||||
|
||||
//#define WT_RENDER_FONT_FILE
|
||||
#ifdef WT_RENDER_FONT_FILE
|
||||
@@ -77,7 +78,7 @@ const i32 asset_loadTextureImage(AssetManager *assetManager,
|
||||
|
||||
Texture tex = texture_gen(CAST(GLuint)(imgWidth), CAST(GLuint)(imgHeight),
|
||||
CAST(GLint)(bytesPerPixel), image);
|
||||
glCheckError();
|
||||
GL_CHECK_ERROR();
|
||||
stbi_image_free(image);
|
||||
|
||||
assetManager->textures[type] = tex;
|
||||
|
||||
+2
-2
@@ -103,7 +103,7 @@ INTERNAL void renderObject(Renderer *renderer, v2 pos, v2 size, v2 pivotPoint,
|
||||
/* Load transformation matrix */
|
||||
shader_use(renderer->shader);
|
||||
shader_uniformSetMat4fv(renderer->shader, "model", model);
|
||||
glCheckError();
|
||||
GL_CHECK_ERROR();
|
||||
|
||||
/* Set color modulation value */
|
||||
shader_uniformSetVec4f(renderer->shader, "spriteColor", color);
|
||||
@@ -132,7 +132,7 @@ INTERNAL void renderObject(Renderer *renderer, v2 pos, v2 size, v2 pivotPoint,
|
||||
/* Unbind */
|
||||
glBindVertexArray(0);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glCheckError();
|
||||
GL_CHECK_ERROR();
|
||||
}
|
||||
|
||||
void renderer_rect(Renderer *const renderer, v4 cameraBounds, v2 pos, v2 size,
|
||||
|
||||
+7
-7
@@ -32,7 +32,7 @@ Texture texture_gen(const GLuint width, const GLuint height,
|
||||
const GLint bytesPerPixel, const u8 *const image)
|
||||
{
|
||||
// TODO(doyle): Let us set the parameters gl params as well
|
||||
glCheckError();
|
||||
GL_CHECK_ERROR();
|
||||
Texture tex = {0};
|
||||
tex.width = width;
|
||||
tex.height = height;
|
||||
@@ -43,21 +43,21 @@ Texture texture_gen(const GLuint width, const GLuint height,
|
||||
tex.filterMagnification = GL_NEAREST;
|
||||
|
||||
glGenTextures(1, &tex.id);
|
||||
glCheckError();
|
||||
GL_CHECK_ERROR();
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, tex.id);
|
||||
glCheckError();
|
||||
GL_CHECK_ERROR();
|
||||
|
||||
/* Load image into texture */
|
||||
// TODO(doyle) Figure out the gl format
|
||||
tex.imageFormat = getGLFormat(bytesPerPixel, FALSE);
|
||||
ASSERT(tex.imageFormat == GL_RGBA);
|
||||
|
||||
glCheckError();
|
||||
GL_CHECK_ERROR();
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, tex.internalFormat, tex.width, tex.height, 0,
|
||||
tex.imageFormat, GL_UNSIGNED_BYTE, image);
|
||||
glCheckError();
|
||||
GL_CHECK_ERROR();
|
||||
|
||||
// TODO(doyle): Not needed for sprites? glGenerateMipmap(GL_TEXTURE_2D);
|
||||
|
||||
@@ -68,11 +68,11 @@ Texture texture_gen(const GLuint width, const GLuint height,
|
||||
tex.filterMinification);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
|
||||
tex.filterMagnification);
|
||||
glCheckError();
|
||||
GL_CHECK_ERROR();
|
||||
|
||||
/* Unbind and clean up */
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glCheckError();
|
||||
GL_CHECK_ERROR();
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
@@ -100,12 +100,12 @@ INTERNAL void rendererInit(GameState *state, v2 windowSize)
|
||||
const mat4 projection =
|
||||
mat4_ortho(0.0f, renderer->size.w, 0.0f, renderer->size.h, 0.0f, 1.0f);
|
||||
shader_uniformSetMat4fv(renderer->shader, "projection", projection);
|
||||
glCheckError();
|
||||
GL_CHECK_ERROR();
|
||||
|
||||
/* Create buffers */
|
||||
glGenVertexArrays(1, &renderer->vao);
|
||||
glGenBuffers(1, &renderer->vbo);
|
||||
glCheckError();
|
||||
GL_CHECK_ERROR();
|
||||
|
||||
/* Bind buffers */
|
||||
glBindBuffer(GL_ARRAY_BUFFER, renderer->vbo);
|
||||
@@ -117,12 +117,12 @@ INTERNAL void rendererInit(GameState *state, v2 windowSize)
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, numVertexElements, GL_FLOAT, GL_FALSE, vertexSize,
|
||||
(GLvoid *)0);
|
||||
glCheckError();
|
||||
GL_CHECK_ERROR();
|
||||
|
||||
/* Unbind */
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
glCheckError();
|
||||
GL_CHECK_ERROR();
|
||||
}
|
||||
|
||||
INTERNAL void addAnim(AssetManager *assetManager, i32 animId, Entity *entity)
|
||||
@@ -206,7 +206,7 @@ void worldTraveller_gameInit(GameState *state, v2 windowSize)
|
||||
shaderlist_sprite);
|
||||
|
||||
asset_loadTTFont(assetManager, arena, "C:/Windows/Fonts/Arialbd.ttf");
|
||||
glCheckError();
|
||||
GL_CHECK_ERROR();
|
||||
|
||||
#ifdef DENGINE_DEBUG
|
||||
DEBUG_LOG("Assets loaded");
|
||||
@@ -578,8 +578,6 @@ INTERNAL void updateEntityAnim(Entity *entity, f32 dt)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(doyle): Exposed because of debug .. rework debug system so it we don't
|
||||
// need to expose any game API to it.
|
||||
INTERNAL v4 createCameraBounds(World *world, v2 size)
|
||||
{
|
||||
v4 result = math_getRect(world->cameraPos, size);
|
||||
@@ -887,7 +885,7 @@ void worldTraveller_gameUpdateAndRender(GameState *state, f32 dt)
|
||||
if (dt >= 1.0f) dt = 1.0f;
|
||||
/* Update */
|
||||
parseInput(state, dt);
|
||||
glCheckError();
|
||||
GL_CHECK_ERROR();
|
||||
|
||||
AssetManager *assetManager = &state->assetManager;
|
||||
Renderer *renderer = &state->renderer;
|
||||
|
||||
+3
-2
@@ -6,6 +6,7 @@ pushd ..\bin
|
||||
set GLEW=..\extern\glew-1.13.0
|
||||
set GLFW=..\extern\glfw-3.2.bin.WIN32
|
||||
set STB=..\extern\stb-master
|
||||
set OAL=..\extern\openal-soft
|
||||
|
||||
REM EHsc enables exception handling
|
||||
REM MD uses dynamic runtime library
|
||||
@@ -13,10 +14,10 @@ REM Zi enables debug data
|
||||
set compileFlags=/EHsc /MD /Zi /W3
|
||||
|
||||
REM Include directories
|
||||
set includeFlags=/I ..\src\include /I %GLEW%\include /I %GLFW%\include /I %STB%\include
|
||||
set includeFlags=/I ..\src\include /I %GLEW%\include /I %GLFW%\include /I %STB%\include /I %OAL%\include
|
||||
|
||||
REM Link libraries
|
||||
set linkLibraries=/link opengl32.lib %GLFW%\lib-vc2015\glfw3.lib %GLEW%\lib\Release\Win32\glew32s.lib gdi32.lib user32.lib shell32.lib
|
||||
set linkLibraries=/link opengl32.lib %GLFW%\lib-vc2015\glfw3.lib %GLEW%\lib\Release\Win32\glew32s.lib %OAL%\lib\Win32\OpenAL32.lib gdi32.lib user32.lib shell32.lib
|
||||
set ignoreLibraries=/NODEFAULTLIB:"libc.lib" /NODEFAULTLIB:"libcmt.lib" /NODEFAULTLIB:"libcd.lib" /NODEFAULTLIB:"libcmtd.lib" /NODEFAULTLIB:"msvcrtd.lib"
|
||||
|
||||
cl %compileFlags% ..\src\*.c %includeFlags% %linkLibraries% %ignoreLibraries% /OUT:"Dengine.exe"
|
||||
|
||||
+91
-2
@@ -1,4 +1,7 @@
|
||||
#if 1
|
||||
#include <OpenAL/al.h>
|
||||
#include <OpenAL/alc.h>
|
||||
|
||||
#include "Dengine/AssetManager.h"
|
||||
#include "Dengine/Common.h"
|
||||
#include "Dengine/Debug.h"
|
||||
@@ -7,6 +10,39 @@
|
||||
|
||||
#include "WorldTraveller/WorldTraveller.h"
|
||||
|
||||
void alCheckError_(const char *file, int line)
|
||||
{
|
||||
|
||||
ALenum errorCode;
|
||||
while ((errorCode = alGetError()) != AL_NO_ERROR)
|
||||
{
|
||||
printf("OPENAL ");
|
||||
switch(errorCode)
|
||||
{
|
||||
case AL_INVALID_NAME:
|
||||
printf("INVALID_NAME | ");
|
||||
break;
|
||||
case AL_INVALID_ENUM:
|
||||
printf("INVALID_ENUM | ");
|
||||
break;
|
||||
case AL_INVALID_VALUE:
|
||||
printf("INVALID_VALUE | ");
|
||||
break;
|
||||
case AL_INVALID_OPERATION:
|
||||
printf("INVALID_OPERATION | ");
|
||||
break;
|
||||
case AL_OUT_OF_MEMORY:
|
||||
printf("OUT_OF_MEMORY | ");
|
||||
break;
|
||||
default:
|
||||
printf("UNRECOGNISED ERROR CODE | ");
|
||||
break;
|
||||
}
|
||||
printf("Error %08x, %s (%d)\n", errorCode, file, line);
|
||||
}
|
||||
};
|
||||
#define AL_CHECK_ERROR() alCheckError_(__FILE__, __LINE__);
|
||||
|
||||
void key_callback(GLFWwindow *window, int key, int scancode, int action, int mode)
|
||||
{
|
||||
GameState *game = CAST(GameState *)(glfwGetWindowUserPointer(window));
|
||||
@@ -31,6 +67,11 @@ void scroll_callback(GLFWwindow *window, double xOffset, double yOffset) {}
|
||||
|
||||
int main()
|
||||
{
|
||||
/*
|
||||
**************************
|
||||
* INIT APPLICATION WINDOW
|
||||
**************************
|
||||
*/
|
||||
glfwInit();
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
@@ -52,6 +93,11 @@ int main()
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
/*
|
||||
**************************
|
||||
* INITIALISE OPENGL STATE
|
||||
**************************
|
||||
*/
|
||||
/* Make GLEW use more modern technies for OGL on core profile*/
|
||||
glewExperimental = GL_TRUE;
|
||||
if (glewInit() != GLEW_OK)
|
||||
@@ -78,6 +124,45 @@ int main()
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
/*
|
||||
*******************
|
||||
* INITIALISE AUDIO
|
||||
*******************
|
||||
*/
|
||||
alGetError();
|
||||
// TODO(doyle): Read this http://www.gamedev.net/page/resources/_/technical/game-programming/basic-openal-sound-manager-for-your-project-r3791
|
||||
ALCdevice *deviceAL = alcOpenDevice(NULL);
|
||||
|
||||
if (!deviceAL)
|
||||
{
|
||||
printf("alcOpenDevice() failed: Failed to init OpenAL device.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ALCcontext *contextAL = alcCreateContext(deviceAL, NULL);
|
||||
alcMakeContextCurrent(contextAL);
|
||||
if (!contextAL)
|
||||
{
|
||||
printf("alcCreateContext() failed: Failed create AL context.\n");
|
||||
return;
|
||||
}
|
||||
AL_CHECK_ERROR();
|
||||
|
||||
#define NUM_BUFFERS 3
|
||||
#define BUFFER_SIZE 4096
|
||||
ALuint audioBufferIds[NUM_BUFFERS];
|
||||
alGenBuffers(NUM_BUFFERS, audioBufferIds);
|
||||
AL_CHECK_ERROR();
|
||||
|
||||
ALuint audioSourcesIds[NUM_BUFFERS];
|
||||
alGenBuffers(NUM_BUFFERS, audioSourcesIds);
|
||||
AL_CHECK_ERROR();
|
||||
|
||||
/*
|
||||
*******************
|
||||
* INITIALISE GAME
|
||||
*******************
|
||||
*/
|
||||
GameState worldTraveller = {0};
|
||||
worldTraveller_gameInit(&worldTraveller,
|
||||
V2i(frameBufferWidth, frameBufferHeight));
|
||||
@@ -103,7 +188,11 @@ int main()
|
||||
glfwSwapInterval(1);
|
||||
#endif
|
||||
|
||||
/* Main game loop */
|
||||
/*
|
||||
*******************
|
||||
* GAME LOOP
|
||||
*******************
|
||||
*/
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
/* Check and call events */
|
||||
@@ -114,7 +203,7 @@ int main()
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
worldTraveller_gameUpdateAndRender(&worldTraveller, secondsElapsed);
|
||||
glCheckError();
|
||||
GL_CHECK_ERROR();
|
||||
|
||||
/* Swap the buffers */
|
||||
glfwSwapBuffers(window);
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "Dengine/MemoryArena.h"
|
||||
#include "Dengine/Shader.h"
|
||||
#include "Dengine/Texture.h"
|
||||
#include "Dengine/MemoryArena.h"
|
||||
|
||||
#define MAX_TEXTURE_SIZE 1024
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define GL_CHECK_ERROR() glCheckError_(__FILE__, __LINE__)
|
||||
inline GLenum glCheckError_(const char *file, int line)
|
||||
{
|
||||
GLenum errorCode;
|
||||
@@ -15,31 +16,30 @@ inline GLenum glCheckError_(const char *file, int line)
|
||||
switch (errorCode)
|
||||
{
|
||||
case GL_INVALID_ENUM:
|
||||
printf("INVALID_ENUM | ");
|
||||
printf("OPENGL INVALID_ENUM | ");
|
||||
break;
|
||||
case GL_INVALID_VALUE:
|
||||
printf("INVALID_VALUE | ");
|
||||
printf("OPENGL INVALID_VALUE | ");
|
||||
break;
|
||||
case GL_INVALID_OPERATION:
|
||||
printf("INVALID_OPERATION | ");
|
||||
printf("OPENGL INVALID_OPERATION | ");
|
||||
break;
|
||||
case GL_STACK_OVERFLOW:
|
||||
printf("STACK_OVERFLOW | ");
|
||||
printf("OPENGL STACK_OVERFLOW | ");
|
||||
break;
|
||||
case GL_STACK_UNDERFLOW:
|
||||
printf("STACK_UNDERFLOW | ");
|
||||
printf("OPENGL STACK_UNDERFLOW | ");
|
||||
break;
|
||||
case GL_OUT_OF_MEMORY:
|
||||
printf("OUT_OF_MEMORY | ");
|
||||
printf("OPENGL OUT_OF_MEMORY | ");
|
||||
break;
|
||||
case GL_INVALID_FRAMEBUFFER_OPERATION:
|
||||
printf("INVALID_FRAMEBUFFER_OPERATION | ");
|
||||
printf("OPENGL INVALID_FRAMEBUFFER_OPERATION | ");
|
||||
break;
|
||||
}
|
||||
printf("%s (%d)\n", file, line);
|
||||
}
|
||||
return errorCode;
|
||||
}
|
||||
#define glCheckError() glCheckError_(__FILE__, __LINE__)
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user