Add mouse tracking, add null-texture gen function

Refactor the creation of the null-texture into a function. Used for
blitting rectangles that don't have any texture associated with it.
This commit is contained in:
Doyle Thai 2016-08-04 18:46:46 +10:00
parent aa505ed0b3
commit adb1aa83f3
3 changed files with 20 additions and 5 deletions

View File

@ -1,4 +1,6 @@
#include "Dengine/Renderer.h"
#include "Dengine/AssetManager.h"
#include "Dengine/Assets.h"
#include "Dengine/Debug.h"
#include "Dengine/Entity.h"
#include "Dengine/OpenGL.h"
@ -138,6 +140,13 @@ INTERNAL void renderObject(Renderer *renderer, v2 pos, v2 size, v2 pivotPoint,
GL_CHECK_ERROR();
}
RenderTex renderer_createNullRenderTex(AssetManager *assetManager)
{
Texture *emptyTex = asset_getTexture(assetManager, texlist_empty);
RenderTex result = {emptyTex, V4(0, 1, 1, 0)};
return result;
}
void renderer_rect(Renderer *const renderer, v4 cameraBounds, v2 pos, v2 size,
v2 pivotPoint, f32 rotate, RenderTex renderTex, v4 color)
{

View File

@ -1124,6 +1124,10 @@ void worldTraveller_gameUpdateAndRender(GameState *state, f32 dt)
}
/* Draw ui */
RenderTex nullRenderTex = renderer_createNullRenderTex(assetManager);
renderer_staticRect(renderer, state->input.mouse, hero->hitboxSize,
V2(0, 0), 0, nullRenderTex, V4(0.5f, 0, 0, 0.5f));
/* Draw hero avatar */
TexAtlas *heroAtlas = asset_getTextureAtlas(assetManager, texlist_hero);
v4 heroAvatarTexRect = heroAtlas->texRect[herorects_head];
@ -1157,9 +1161,8 @@ void worldTraveller_gameUpdateAndRender(GameState *state, f32 dt)
f32 angle = math_atan2f(difference.y, difference.x);
f32 angleDegrees = RADIANS_TO_DEGREES(angle);
Texture *emptyTex = asset_getTexture(assetManager, texlist_empty);
v2 heroCenter = v2_add(hero->pos, v2_scale(hero->hitboxSize, 0.5f));
RenderTex renderTex = {emptyTex, V4(0, 1, 1, 0)};
RenderTex renderTex = renderer_createNullRenderTex(assetManager);
f32 distance = v2_magnitude(hero->pos, entity->pos);
renderer_rect(&state->renderer, cameraBounds, heroCenter,
V2(distance, 2.0f), V2(0, 0), angle, renderTex,

View File

@ -5,11 +5,12 @@
#include "Dengine/Math.h"
/* Forward Declaration */
typedef struct Shader Shader;
typedef struct AssetManager AssetManager;
typedef struct Entity Entity;
typedef struct MemoryArena MemoryArena;
typedef struct Texture Texture;
typedef struct Font Font;
typedef struct MemoryArena MemoryArena;
typedef struct Shader Shader;
typedef struct Texture Texture;
typedef struct Renderer
{
@ -27,6 +28,8 @@ typedef struct RenderTex
v4 texRect;
} RenderTex;
RenderTex renderer_createNullRenderTex(AssetManager *assetManager);
// TODO(doyle): Clean up lines
// Renderer::~Renderer() { glDeleteVertexArrays(1, &this->quadVAO); }
void renderer_rect(Renderer *const renderer, v4 cameraBounds, v2 pos, v2 size,