23 changes: 16 additions & 7 deletions lib/ivis_opengl/pieblitfunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "lib/framework/string_ext.h"
#include "piedef.h"
#include "piepalette.h"
#include <glm/gtx/transform.hpp>
#include "pieclip.h"

/***************************************************************************/
/*
Expand Down Expand Up @@ -85,7 +87,7 @@ class GFX
void buffers(int vertices, const GLvoid *vertBuf, const GLvoid *texBuf);

/// Draw everything
void draw();
void draw(const glm::mat4 &modelViewProjectionMatrix);

private:
GFXTYPE mType;
Expand All @@ -104,6 +106,13 @@ class GFX
* Global ProtoTypes
*/
/***************************************************************************/
static inline glm::mat4 defaultProjectionMatrix()
{
float w = pie_GetVideoBufferWidth();
float h = pie_GetVideoBufferHeight();

return glm::ortho(0.f, static_cast<float>(w), static_cast<float>(h), 0.f);
}
void iV_ShadowBox(int x0, int y0, int x1, int y1, int pad, PIELIGHT first, PIELIGHT second, PIELIGHT fill);
extern void iV_Line(int x0, int y0, int x1, int y1, PIELIGHT colour);
extern void iV_Box2(int x0, int y0, int x1, int y1, PIELIGHT first, PIELIGHT second);
Expand All @@ -112,12 +121,12 @@ static inline void iV_Box(int x0, int y0, int x1, int y1, PIELIGHT first)
iV_Box2(x0, y0, x1, y1, first, first);
}
extern void pie_BoxFill(int x0, int y0, int x1, int y1, PIELIGHT colour, REND_MODE rendermode = REND_OPAQUE);
extern void iV_DrawImage(GLuint TextureID, Vector2i position, Vector2i size, REND_MODE mode, PIELIGHT colour);
extern void iV_DrawImage(IMAGEFILE *ImageFile, UWORD ID, int x, int y);
extern void iV_DrawImage(GLuint TextureID, Vector2i position, Vector2i offset, Vector2i size, float angle, REND_MODE mode, PIELIGHT colour);
extern void iV_DrawImage(IMAGEFILE *ImageFile, UWORD ID, int x, int y, const glm::mat4 &modelViewProjection = defaultProjectionMatrix());
void iV_DrawImage2(const QString &filename, float x, float y, float width = -0.0f, float height = -0.0f);
void iV_DrawImageTc(Image image, Image imageTc, int x, int y, PIELIGHT colour);
void iV_DrawImageRepeatX(IMAGEFILE *ImageFile, UWORD ID, int x, int y, int Width);
void iV_DrawImageRepeatY(IMAGEFILE *ImageFile, UWORD ID, int x, int y, int Height);
void iV_DrawImageTc(Image image, Image imageTc, int x, int y, PIELIGHT colour, const glm::mat4 &modelViewProjection = defaultProjectionMatrix());
void iV_DrawImageRepeatX(IMAGEFILE *ImageFile, UWORD ID, int x, int y, int Width, const glm::mat4 &modelViewProjection = defaultProjectionMatrix());
void iV_DrawImageRepeatY(IMAGEFILE *ImageFile, UWORD ID, int x, int y, int Height, const glm::mat4 &modelViewProjection = defaultProjectionMatrix());

static inline void iV_DrawImage(Image image, int x, int y)
{
Expand All @@ -134,7 +143,7 @@ extern void pie_UniTransBoxFill(float x0, float y0, float x1, float y1, PIELIGHT
bool pie_InitRadar();
bool pie_ShutdownRadar();
void pie_DownLoadRadar(UDWORD *buffer);
void pie_RenderRadar();
void pie_RenderRadar(const glm::mat4 &modelViewProjectionMatrix);
void pie_SetRadar(GLfloat x, GLfloat y, GLfloat width, GLfloat height, int twidth, int theight, bool filter);

enum SCREENTYPE
Expand Down
12 changes: 7 additions & 5 deletions lib/ivis_opengl/piefunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ void pie_SetViewingWindow(Vector3i *v, PIELIGHT colour)
radarViewGfx[1]->buffers(VW_VERTICES, vert, cols);
}

void pie_DrawViewingWindow()
void pie_DrawViewingWindow(const glm::mat4 &modelViewProjectionMatrix)
{
pie_SetRendMode(REND_ALPHA);
radarViewGfx[0]->draw();
radarViewGfx[1]->draw();
radarViewGfx[0]->draw(modelViewProjectionMatrix);
radarViewGfx[1]->draw(modelViewProjectionMatrix);
}

void pie_TransColouredTriangle(Vector3f *vrt, PIELIGHT c)
Expand Down Expand Up @@ -198,8 +198,10 @@ void pie_DrawSkybox(float scale)

// Apply scale matrix
glScalef(scale, scale / 2.0f, scale);

skyboxGfx->draw();
GLfloat p[16], vm[16];
glGetFloatv(GL_PROJECTION_MATRIX, p);
glGetFloatv(GL_MODELVIEW_MATRIX, vm);
skyboxGfx->draw(glm::make_mat4(p) * glm::make_mat4(vm));

glPopAttrib();
}
2 changes: 1 addition & 1 deletion lib/ivis_opengl/piefunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
void pie_TransColouredTriangle(Vector3f *vrt, PIELIGHT c);

void pie_SetViewingWindow(Vector3i *v, PIELIGHT colour);
void pie_DrawViewingWindow();
void pie_DrawViewingWindow(const glm::mat4 &modelViewProjectionMatrix);

void pie_DrawSkybox(float scale);
void pie_Skybox_Init();
Expand Down
22 changes: 22 additions & 0 deletions lib/ivis_opengl/piestate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,28 @@ bool pie_LoadShaders()
"fogEnabled", "fogEnd", "fogStart" });
ASSERT_OR_RETURN(false, result, "Failed to load water shader");

// Rectangular shader
debug(LOG_3D, "Loading shader: RECT");
result = pie_LoadShader("Rect program", "shaders/rect.vert", "shaders/rect.frag",
{ "transformationMatrix", "color" });
ASSERT_OR_RETURN(false, result, "Failed to load rect shader");

// Textured rectangular shader
debug(LOG_3D, "Loading shader: TEXRECT");
result = pie_LoadShader("Rect program", "shaders/rect.vert", "shaders/texturedrect.frag",
{ "transformationMatrix", "tuv_offset", "tuv_scale", "color", "texture" });
ASSERT_OR_RETURN(false, result, "Failed to load textured rect shader");

debug(LOG_3D, "Loading shader: GFX_COLOR");
result = pie_LoadShader("gfx_color program", "shaders/gfx.vert", "shaders/gfx.frag",
{ "posMatrix" });
ASSERT_OR_RETURN(false, result, "Failed to load textured gfx shader");

debug(LOG_3D, "Loading shader: GFX_TEXT");
result = pie_LoadShader("gfx_text program", "shaders/gfx.vert", "shaders/texturedrect.frag",
{ "posMatrix", "texture" });
ASSERT_OR_RETURN(false, result, "Failed to load textured gfx shader");

pie_internal::currentShaderMode = SHADER_NONE;
return true;
}
Expand Down
4 changes: 4 additions & 0 deletions lib/ivis_opengl/pietypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ enum SHADER_MODE
SHADER_TERRAIN_DEPTH,
SHADER_DECALS,
SHADER_WATER,
SHADER_RECT,
SHADER_TEXRECT,
SHADER_GFX_COLOUR,
SHADER_GFX_TEXT,
SHADER_MAX
};

Expand Down
4 changes: 2 additions & 2 deletions lib/ivis_opengl/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include <string>
#include <vector>
#include <cstring>
#include <glm/gtx/transform.hpp>

//using namespace std;

Expand Down Expand Up @@ -483,8 +484,7 @@ void screen_Display()
pie_SetDepthBufferStatus(DEPTH_CMP_ALWAYS_WRT_OFF);

// Draw backdrop
glColor3f(1, 1, 1);
backdropGfx->draw();
backdropGfx->draw(glm::ortho(0.f, (float)pie_GetVideoBufferWidth(), (float)pie_GetVideoBufferHeight(), 0.f));

if (mappreview)
{
Expand Down
22 changes: 3 additions & 19 deletions lib/ivis_opengl/textdraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,26 +657,14 @@ int iV_DrawFormattedText(const char *String, UDWORD x, UDWORD y, UDWORD Width, U

void iV_DrawTextRotated(const char *string, float XPos, float YPos, float rotation)
{
GLint matrix_mode = 0;
ASSERT_OR_RETURN(, string, "Couldn't render string!");
pie_SetTexturePage(TEXPAGE_EXTERN);

glGetIntegerv(GL_MATRIX_MODE, &matrix_mode);
glMatrixMode(GL_TEXTURE);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();

if (rotation != 0.f)
{
rotation = 180. - rotation;
}

glTranslatef(floor(XPos), floor(YPos), 0.f);
glRotatef(rotation, 0.f, 0.f, 1.f);

glColor4fv(font_colour);
PIELIGHT color;
color.vector[0] = font_colour[0] * 255.f;
color.vector[1] = font_colour[1] * 255.f;
Expand All @@ -700,15 +688,11 @@ void iV_DrawTextRotated(const char *string, float XPos, float YPos, float rotati
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

iV_DrawImage(textureID, Vector2i(xoffset, yoffset), Vector2i(width, height), REND_TEXT, color);
glDisable(GL_CULL_FACE);
iV_DrawImage(textureID, Vector2i(XPos, YPos), Vector2i(xoffset, yoffset), Vector2i(width, height), rotation, REND_TEXT, color);
glEnable(GL_CULL_FACE);
}

glPopMatrix();
glMatrixMode(GL_TEXTURE);
glPopMatrix();
glMatrixMode(matrix_mode);

// Reset the current model view matrix
glLoadIdentity();
}
Expand Down
11 changes: 6 additions & 5 deletions lib/sequence/sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
#include "lib/sound/audio.h"
#include "lib/sound/openal_error.h"
#include "lib/sound/mixer.h"
#include <glm/gtx/transform.hpp>
#include "lib/ivis_opengl/pieclip.h"

#include <theora/theora.h>
#include <physfs.h>
Expand Down Expand Up @@ -382,12 +384,11 @@ static void video_write(bool update)
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);

glPushMatrix();
glTranslatef(Scrnvidpos[0], Scrnvidpos[1], Scrnvidpos[2]);
videoGfx->draw(
glm::ortho(0.f, static_cast<float>(pie_GetVideoBufferWidth()), static_cast<float>(pie_GetVideoBufferHeight()), 0.f) *
glm::translate(glm::vec3(Scrnvidpos[0], Scrnvidpos[1], Scrnvidpos[2]))
);

videoGfx->draw();

glPopMatrix();
glErrors();
}

Expand Down
6 changes: 3 additions & 3 deletions src/intdisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2045,7 +2045,7 @@ void IntTransportButton::display(int xOffset, int yOffset)
}

/* Draws blips on radar to represent Proximity Display and damaged structures */
void drawRadarBlips(int radarX, int radarY, float pixSizeH, float pixSizeV)
void drawRadarBlips(int radarX, int radarY, float pixSizeH, float pixSizeV, const glm::mat4 &modelViewProjection)
{
PROXIMITY_DISPLAY *psProxDisp;
UWORD imageID;
Expand Down Expand Up @@ -2168,7 +2168,7 @@ void drawRadarBlips(int radarX, int radarY, float pixSizeH, float pixSizeV)
&& (y + radarY) < height * pixSizeH / 2 && (y + radarY) > -height * pixSizeH / 2)
{
// Draw the 'blip'
iV_DrawImage(IntImages, imageID, x + radarX, y + radarY);
iV_DrawImage(IntImages, imageID, x + radarX, y + radarY, modelViewProjection);
}
}
if (audio_GetPreviousQueueTrackRadarBlipPos(&x, &y))
Expand All @@ -2186,7 +2186,7 @@ void drawRadarBlips(int radarX, int radarY, float pixSizeH, float pixSizeV)
&& (y + radarY) < height * pixSizeH / 2 && (y + radarY) > -height * pixSizeH / 2)
{
// Draw the 'blip'
iV_DrawImage(IntImages, imageID, x + radarX, y + radarY);
iV_DrawImage(IntImages, imageID, x + radarX, y + radarY, modelViewProjection);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/intdisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class IntTransportButton : public IntFancyButton
};

/*draws blips on radar to represent Proximity Display*/
extern void drawRadarBlips(int radarX, int radarY, float pixSizeH, float pixSizeV);
extern void drawRadarBlips(int radarX, int radarY, float pixSizeH, float pixSizeV, const glm::mat4 &modelViewProjection);

/*Displays the proximity messages blips over the world*/
void intDisplayProximityBlips(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset);
Expand Down
10 changes: 5 additions & 5 deletions src/intimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ bool imageInitBitmaps(void)

// Render a window frame.
//
void RenderWindowFrame(FRAMETYPE frame, UDWORD x, UDWORD y, UDWORD Width, UDWORD Height)
void RenderWindowFrame(FRAMETYPE frame, UDWORD x, UDWORD y, UDWORD Width, UDWORD Height, const glm::mat4 &modelViewProjectionMatrix)
{
SWORD WTopRight = 0;
SWORD WTopLeft = 0;
Expand Down Expand Up @@ -241,24 +241,24 @@ void RenderWindowFrame(FRAMETYPE frame, UDWORD x, UDWORD y, UDWORD Width, UDWORD
if (Frame->TopEdge >= 0)
{
iV_DrawImageRepeatX(IntImages, Frame->TopEdge, x + iV_GetImageWidth(IntImages, Frame->TopLeft), y,
Width - WTopLeft - WTopRight);
Width - WTopLeft - WTopRight, modelViewProjectionMatrix);
}

if (Frame->BottomEdge >= 0)
{
iV_DrawImageRepeatX(IntImages, Frame->BottomEdge, x + WBottomLeft, y + Height - iV_GetImageHeight(IntImages, Frame->BottomEdge),
Width - WBottomLeft - WBottomRight);
Width - WBottomLeft - WBottomRight, modelViewProjectionMatrix);
}

if (Frame->LeftEdge >= 0)
{
iV_DrawImageRepeatY(IntImages, Frame->LeftEdge, x, y + HTopLeft, Height - HTopLeft - HBottomLeft);
iV_DrawImageRepeatY(IntImages, Frame->LeftEdge, x, y + HTopLeft, Height - HTopLeft - HBottomLeft, modelViewProjectionMatrix);
}

if (Frame->RightEdge >= 0)
{
iV_DrawImageRepeatY(IntImages, Frame->RightEdge, x + Width - iV_GetImageWidth(IntImages, Frame->RightEdge), y + HTopRight,
Height - HTopRight - HBottomRight);
Height - HTopRight - HBottomRight, modelViewProjectionMatrix);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/intimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ extern IMAGEFILE *IntImages; //< All the 2d graphics for the user interface.
bool imageInitBitmaps(void);

/** Draws a transparent window. */
void RenderWindowFrame(FRAMETYPE frame, UDWORD x, UDWORD y, UDWORD Width, UDWORD Height);
void RenderWindowFrame(FRAMETYPE frame, uint32_t x, uint32_t y, uint32_t Width, uint32_t Heig, const glm::mat4 &modelViewProjection = glm::mat4());

#endif
35 changes: 17 additions & 18 deletions src/radar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "multiplay.h"
#include "intdisplay.h"
#include "texture.h"
#include <glm/gtx/transform.hpp>

#define HIT_NOTIFICATION (GAME_TICKS_PER_SEC * 2)
#define RADAR_FRAME_SKIP 10
Expand Down Expand Up @@ -110,8 +111,8 @@ static int frameSkip = 0;

static void DrawRadarTiles();
static void DrawRadarObjects();
static void DrawRadarExtras();
static void DrawNorth();
static void DrawRadarExtras(const glm::mat4 &modelViewProjectionMatrix);
static void DrawNorth(const glm::mat4 &modelViewProjectionMatrix);
static void setViewingWindow();

static void radarSize(int ZoomLevel)
Expand Down Expand Up @@ -282,26 +283,24 @@ void drawRadar()
}
frameSkip--;
pie_SetRendMode(REND_ALPHA);
pie_MatBegin();
pie_TRANSLATE(radarCenterX, radarCenterY, 0);
glm::mat4 radarMatrix =
glm::translate(static_cast<float>(radarCenterX), static_cast<float>(radarCenterY), 0.f);
glm::mat4 orthoMatrix = glm::ortho(0.f, static_cast<float>(pie_GetVideoBufferWidth()), static_cast<float>(pie_GetVideoBufferHeight()), 0.f);
if (rotateRadar)
{
// rotate the map
pie_MatRotZ(player.r.y);
DrawNorth();
radarMatrix *= glm::rotate(UNDEG(player.r.y), glm::vec3(0.f, 0.f, 1.f));
DrawNorth(orthoMatrix * radarMatrix);
}
pie_RenderRadar();
pie_MatBegin();
pie_TRANSLATE(-radarWidth / 2 - 1, -radarHeight / 2 - 1, 0);
DrawRadarExtras();
pie_MatEnd();
drawRadarBlips(-radarWidth / 2.0 - 1, -radarHeight / 2.0 - 1, pixSizeH, pixSizeV);
pie_MatEnd();

pie_RenderRadar(orthoMatrix * radarMatrix);
DrawRadarExtras(orthoMatrix * radarMatrix * glm::translate(-radarWidth / 2.f - 1.f, -radarHeight / 2.f - 1.f, 0.f));
drawRadarBlips(-radarWidth / 2.0 - 1, -radarHeight / 2.0 - 1, pixSizeH, pixSizeV, orthoMatrix * radarMatrix);
}

static void DrawNorth()
static void DrawNorth(const glm::mat4 &modelViewProjectionMatrix)
{
iV_DrawImage(IntImages, RADAR_NORTH, -((radarWidth / 2.0) + iV_GetImageWidth(IntImages, RADAR_NORTH) + 1), -(radarHeight / 2.0));
iV_DrawImage(IntImages, RADAR_NORTH, -((radarWidth / 2.0) + iV_GetImageWidth(IntImages, RADAR_NORTH) + 1), -(radarHeight / 2.0), modelViewProjectionMatrix);
}

static PIELIGHT appliedRadarColour(RADAR_DRAW_MODE radarDrawMode, MAPTILE *WTile)
Expand Down Expand Up @@ -645,10 +644,10 @@ static void setViewingWindow()
pie_SetViewingWindow(tv, colour);
}

static void DrawRadarExtras()
static void DrawRadarExtras(const glm::mat4 &modelViewProjectionMatrix)
{
pie_DrawViewingWindow();
RenderWindowFrame(FRAME_RADAR, -1, -1, radarWidth + 2, radarHeight + 2);
pie_DrawViewingWindow(modelViewProjectionMatrix);
RenderWindowFrame(FRAME_RADAR, -1, -1, radarWidth + 2, radarHeight + 2, modelViewProjectionMatrix);
}

/** Does a screen coordinate lie within the radar area? */
Expand Down
2 changes: 1 addition & 1 deletion src/wrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ void loadingScreenCallback(void)
for (i = 1; i < starsNum; ++i)
{
stars[i].xPos = stars[i].xPos + stars[i].speed;
if (stars[i].xPos >= barRightX)
if (barLeftX + stars[i].xPos >= barRightX)
{
stars[i] = newStar();
stars[i].xPos = 1;
Expand Down