Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: Warzone2100/warzone2100
base: 6291df3cd3
...
head fork: Warzone2100/warzone2100
compare: 9930a76c12
  • 5 commits
  • 17 files changed
  • 0 commit comments
  • 1 contributor
View
8 data/base/script/rules.js
@@ -2,6 +2,14 @@
//
// * Enable unit design and minimap only when an HQ exists
+function eventGameInit()
+{
+ if (tilesetType != "ARIZONA")
+ {
+ setSky("texpages/page-25-sky-urban.png", 0.5, 10000.0);
+ }
+}
+
function eventStartLevel()
{
// Disable by default
View
5 data/mp/multiplay/skirmish/rules.js
@@ -10,6 +10,11 @@ var lastHitTime = 0;
function eventGameInit()
{
+ if (tilesetType != "ARIZONA")
+ {
+ setSky("texpages/page-25-sky-urban.png", 0.5, 10000.0);
+ }
+
hackNetOff();
for (var playnum = 0; playnum < maxPlayers; playnum++)
{
View
137 lib/ivis_opengl/pieblitfunc.cpp
@@ -52,9 +52,7 @@
#define pie_FILLBLUE 128
#define pie_FILLTRANS 128
-static GLuint radarTexture;
-static GLuint radarSizeX, radarSizeY;
-static GLfloat radarTexX, radarTexY;
+static GFX *radarGfx = NULL;
struct PIERECT ///< Screen rectangle.
{
@@ -67,6 +65,81 @@ struct PIERECT ///< Screen rectangle.
*/
/***************************************************************************/
+GFX::GFX(GLenum drawType, int coordsPerVertex) : mdrawType(drawType), mCoordsPerVertex(coordsPerVertex), mSize(0)
+{
+ glGenBuffers(VBO_MINIMAL, mBuffers);
+ glGenTextures(1, &mTexture);
+}
+
+void GFX::loadTexture(const char *filename, GLenum filter)
+{
+ const char *extension = strrchr(filename, '.'); // determine the filetype
+ iV_Image image;
+ if (!extension || strcmp(extension, ".png") != 0)
+ {
+ debug(LOG_ERROR, "Bad image filename: %s", filename);
+ return;
+ }
+ if (iV_loadImage_PNG(filename, &image))
+ {
+ makeTexture(image.width, image.height, filter, iV_getPixelFormat(&image), image.bmp);
+ iV_unloadImage(&image);
+ }
+}
+
+void GFX::makeTexture(int width, int height, GLenum filter, GLenum format, const GLvoid *image)
+{
+ pie_SetTexturePage(TEXPAGE_EXTERN);
+ glBindTexture(GL_TEXTURE_2D, mTexture);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, format, GL_UNSIGNED_BYTE, image);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+ mWidth = width;
+ mHeight = height;
+ mFormat = format;
+}
+
+void GFX::updateTexture(const void *image, int width, int height)
+{
+ if (width == -1) width = mWidth;
+ if (height == -1) height = mHeight;
+ pie_SetTexturePage(TEXPAGE_EXTERN);
+ glBindTexture(GL_TEXTURE_2D, mTexture);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, mFormat, GL_UNSIGNED_BYTE, image);
+}
+
+void GFX::buffers(int vertices, const GLvoid *vertBuf, const GLvoid *texBuf)
+{
+ glBindBuffer(GL_ARRAY_BUFFER, mBuffers[VBO_TEXCOORD]);
+ glBufferData(GL_ARRAY_BUFFER, vertices * 2 * sizeof(GLfloat), texBuf, GL_STATIC_DRAW);
+ glBindBuffer(GL_ARRAY_BUFFER, mBuffers[VBO_VERTEX]);
+ glBufferData(GL_ARRAY_BUFFER, vertices * mCoordsPerVertex * sizeof(GLfloat), vertBuf, GL_STATIC_DRAW);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ mSize = vertices;
+}
+
+void GFX::draw()
+{
+ pie_SetTexturePage(TEXPAGE_EXTERN);
+ glBindTexture(GL_TEXTURE_2D, mTexture);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glBindBuffer(GL_ARRAY_BUFFER, mBuffers[VBO_TEXCOORD]); glTexCoordPointer(2, GL_FLOAT, 0, NULL);
+ glBindBuffer(GL_ARRAY_BUFFER, mBuffers[VBO_VERTEX]); glVertexPointer(mCoordsPerVertex, GL_FLOAT, 0, NULL);
+ glDrawArrays(mdrawType, 0, mSize);
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+}
+
+GFX::~GFX()
+{
+ glDeleteBuffers(VBO_MINIMAL, mBuffers);
+ glDeleteTextures(1, &mTexture);
+}
+
void iV_Line(int x0, int y0, int x1, int y1, PIELIGHT colour)
{
pie_SetTexturePage(TEXPAGE_NONE);
@@ -347,63 +420,49 @@ void iV_DrawImageScaled(IMAGEFILE *ImageFile, UWORD ID, int x, int y, int w, int
bool pie_InitRadar(void)
{
- glGenTextures(1, &radarTexture);
+ radarGfx = new GFX(GL_TRIANGLE_STRIP, 2);
return true;
}
bool pie_ShutdownRadar(void)
{
- glDeleteTextures(1, &radarTexture);
+ delete radarGfx;
+ radarGfx = NULL;
return true;
}
-/** Store radar texture with given width and height. */
-void pie_DownLoadRadar(UDWORD *buffer, int width, int height, bool filter)
+void pie_SetRadar(GLfloat x, GLfloat y, GLfloat width, GLfloat height, int twidth, int theight, bool filter)
{
int w = 1, h = 1;
char *black;
/* Find power of two size */
- while (width > (w *= 2)) {}
- while (height > (h *= 2)) {}
+ while (twidth > (w *= 2)) {}
+ while (theight > (h *= 2)) {}
- pie_SetTexturePage(TEXPAGE_EXTERN);
- glBindTexture(GL_TEXTURE_2D, radarTexture);
black = (char *)calloc(1, w * h * 4);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, black);
+ radarGfx->makeTexture(twidth, theight, filter ? GL_LINEAR : GL_NEAREST, GL_RGBA, black);
free(black);
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
- if (filter)
- {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- }
- else
- {
- 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_WRAP_S, GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
- radarSizeX = width;
- radarSizeY = height;
- radarTexX = ((GLfloat)width / (GLfloat)w);
- radarTexY = ((GLfloat)height / (GLfloat)h);
+
+ GLfloat radarTexX = ((GLfloat)twidth / (GLfloat)w);
+ GLfloat radarTexY = ((GLfloat)theight / (GLfloat)h);
+ GLfloat texcoords[] = { 0.0f, 0.0f, radarTexX, 0.0f, 0.0f, radarTexY, radarTexX, radarTexY };
+ GLfloat vertices[] = { x, y, x + width, y, x, y + height, x + width, y + height };
+ radarGfx->buffers(4, vertices, texcoords);
+}
+
+/** Store radar texture with given width and height. */
+void pie_DownLoadRadar(UDWORD *buffer)
+{
+ radarGfx->updateTexture(buffer);
}
/** Display radar texture using the given height and width, depending on zoom level. */
-void pie_RenderRadar(int x, int y, int width, int height)
+void pie_RenderRadar()
{
- pie_SetTexturePage(TEXPAGE_EXTERN);
- glBindTexture(GL_TEXTURE_2D, radarTexture);
pie_SetRendMode(REND_ALPHA);
- glColor4ubv(WZCOL_WHITE.vector);
- glBegin(GL_TRIANGLE_STRIP);
- glTexCoord2f(0, 0); glVertex2f(x, y);
- glTexCoord2f(radarTexX, 0); glVertex2f(x + width, y);
- glTexCoord2f(0, radarTexY); glVertex2f(x, y + height);
- glTexCoord2f(radarTexX, radarTexY); glVertex2f(x + width, y + height);
- glEnd();
+ glColor4ubv(WZCOL_WHITE.vector); // hack
+ radarGfx->draw();
}
void pie_LoadBackDrop(SCREENTYPE screenType)
View
48 lib/ivis_opengl/pieblitfunc.h
@@ -49,10 +49,47 @@
/***************************************************************************/
/*
- * Global Variables
+ * Global Classes
*/
/***************************************************************************/
+/// Generic graphics using VBOs drawing class
+class GFX
+{
+public:
+ /// Initialize class and allocate GPU resources
+ GFX(GLenum drawType = GL_TRIANGLES, int coordsPerVertex = 3);
+
+ /// Destroy GPU held resources
+ ~GFX();
+
+ /// Load texture data from file, allocate space for it, and put it on the GPU
+ void loadTexture(const char *filename, GLenum filter = GL_LINEAR);
+
+ /// Allocate space on the GPU for texture of given parameters. If image is non-NULL,
+ /// then that memory buffer is uploaded to the GPU.
+ void makeTexture(int width, int height, GLenum filter = GL_LINEAR, GLenum format = GL_RGBA, const GLvoid *image = NULL);
+
+ /// Upload given memory buffer to already allocated texture space on the GPU
+ void updateTexture(const GLvoid *image, int width = -1, int height = -1);
+
+ /// Upload vertex and texture buffer data to the GPU
+ void buffers(int vertices, const GLvoid *vertBuf, const GLvoid *texBuf);
+
+ /// Draw everything
+ void draw();
+
+private:
+ GLenum mFormat;
+ int mWidth;
+ int mHeight;
+ GLenum mdrawType;
+ int mCoordsPerVertex;
+ GLuint mBuffers[VBO_COUNT];
+ GLuint mTexture;
+ int mSize;
+};
+
/***************************************************************************/
/*
* Global ProtoTypes
@@ -75,10 +112,11 @@ static inline void iV_DrawImageScaled(Image image, int x, int y, int w, int h) {
extern void iV_TransBoxFill(float x0, float y0, float x1, float y1);
extern void pie_UniTransBoxFill(float x0, float y0, float x1, float y1, PIELIGHT colour);
-extern bool pie_InitRadar(void);
-extern bool pie_ShutdownRadar(void);
-extern void pie_DownLoadRadar(UDWORD *buffer, int width, int height, bool filter);
-extern void pie_RenderRadar(int x, int y, int width, int height);
+bool pie_InitRadar();
+bool pie_ShutdownRadar();
+void pie_DownLoadRadar(UDWORD *buffer);
+void pie_RenderRadar();
+void pie_SetRadar(GLfloat x, GLfloat y, GLfloat width, GLfloat height, int twidth, int theight, bool filter);
enum SCREENTYPE
{
View
28 lib/ivis_opengl/piefunc.cpp
@@ -31,9 +31,10 @@
#include "lib/ivis_opengl/piestate.h"
#include "piematrix.h"
#include "lib/ivis_opengl/piemode.h"
+#include "lib/ivis_opengl/pieblitfunc.h"
#include "lib/ivis_opengl/pieclip.h"
-static GLuint skyboxbuffers[VBO_MINIMAL];
+static GFX *skyboxGfx = NULL;
#define VW_VERTICES 5
void pie_DrawViewingWindow(Vector3i *v, UDWORD x1, UDWORD y1, UDWORD x2, UDWORD y2, PIELIGHT colour)
@@ -119,17 +120,19 @@ void pie_Skybox_Init()
u + w * 8, v + h, u + w * 8, v };
GL_DEBUG("Initializing skybox");
- glGenBuffers(VBO_MINIMAL, skyboxbuffers);
- glBindBuffer(GL_ARRAY_BUFFER, skyboxbuffers[VBO_VERTEX]);
- glBufferData(GL_ARRAY_BUFFER, sizeof(vert), vert, GL_STATIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER, skyboxbuffers[VBO_TEXCOORD]);
- glBufferData(GL_ARRAY_BUFFER, sizeof(texc), texc, GL_STATIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
+ skyboxGfx = new GFX(GL_QUAD_STRIP, 3);
+ skyboxGfx->buffers(10, vert, texc);
+}
+
+void pie_Skybox_Texture(const char *filename)
+{
+ skyboxGfx->loadTexture(filename);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
}
void pie_Skybox_Shutdown()
{
- glDeleteBuffers(VBO_MINIMAL, skyboxbuffers);
+ delete skyboxGfx;
}
void pie_DrawSkybox(float scale)
@@ -155,14 +158,7 @@ void pie_DrawSkybox(float scale)
// Apply scale matrix
glScalef(scale, scale/2.0f, scale);
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glBindBuffer(GL_ARRAY_BUFFER, skyboxbuffers[VBO_VERTEX]); glVertexPointer(3, GL_FLOAT, 0, NULL);
- glBindBuffer(GL_ARRAY_BUFFER, skyboxbuffers[VBO_TEXCOORD]); glTexCoordPointer(2, GL_FLOAT, 0, NULL);
- glDrawArrays(GL_QUAD_STRIP, 0, 10);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ skyboxGfx->draw();
glPopAttrib();
}
View
1  lib/ivis_opengl/piefunc.h
@@ -40,5 +40,6 @@ extern void pie_DrawViewingWindow( Vector3i *v, UDWORD x1, UDWORD y1, UDWORD x2,
void pie_DrawSkybox(float scale);
void pie_Skybox_Init();
void pie_Skybox_Shutdown();
+void pie_Skybox_Texture(const char *filename);
#endif // _piedef_h
View
83 lib/ivis_opengl/screen.cpp
@@ -52,9 +52,8 @@ int wz_texture_compression = 0;
static bool bBackDrop = false;
static char screendump_filename[PATH_MAX];
static bool screendump_required = false;
-static GLuint backDropTexture = 0;
-static GLuint buffers[VBO_COUNT];
+static GFX *backdropGfx = NULL;
static int preview_width = 0, preview_height = 0;
static Vector2i player_pos[MAX_PLAYERS];
@@ -184,9 +183,8 @@ bool screenInitialise()
pie_Skybox_Init();
- // Generate backdrop buffers
- glGenBuffers(VBO_MINIMAL, buffers);
- glGenTextures(1, &backDropTexture);
+ // Generate backdrop render
+ backdropGfx = new GFX(GL_TRIANGLE_STRIP, 2);
glErrors();
return true;
@@ -196,8 +194,7 @@ void screenShutDown(void)
{
pie_Skybox_Shutdown();
- glDeleteBuffers(VBO_MINIMAL, buffers);
- glDeleteTextures(1, &backDropTexture);
+ delete backdropGfx;
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
@@ -265,39 +262,8 @@ void screen_EnableMissingFunctions()
void screen_SetBackDropFromFile(const char* filename)
{
- // HACK : We should use a resource handler here!
- const char *extension = strrchr(filename, '.');// determine the filetype
- iV_Image image;
-
- if(!extension)
- {
- debug(LOG_ERROR, "Image without extension: \"%s\"!", filename);
- return; // filename without extension... don't bother
- }
-
- // Make sure the current texture page is reloaded after we are finished
- // Otherwise WZ will think it is still loaded and not load it again
- pie_SetTexturePage(TEXPAGE_EXTERN);
-
- if (strcmp(extension, ".png") == 0)
- {
- if (iV_loadImage_PNG(filename, &image))
- {
- glBindTexture(GL_TEXTURE_2D, backDropTexture);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width, image.height,
- 0, iV_getPixelFormat(&image), GL_UNSIGNED_BYTE, image.bmp);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
- iV_unloadImage(&image);
- screen_Upload(NULL);
- }
- }
- else
- {
- debug(LOG_ERROR, "Unknown extension \"%s\" for image \"%s\"!", extension, filename);
- }
+ backdropGfx->loadTexture(filename);
+ screen_Upload(NULL);
}
void screen_StopBackDrop(void)
@@ -319,22 +285,9 @@ void screen_Display()
{
pie_SetDepthBufferStatus(DEPTH_CMP_ALWAYS_WRT_OFF);
- // Make sure the current texture page is reloaded after we are finished
- // Otherwise WZ will think it is still loaded and not load it again
- pie_SetTexturePage(TEXPAGE_EXTERN);
- glBindTexture(GL_TEXTURE_2D, backDropTexture);
-
// Draw backdrop
glColor3f(1, 1, 1);
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glBindBuffer(GL_ARRAY_BUFFER, buffers[VBO_TEXCOORD]); glTexCoordPointer(2, GL_FLOAT, 0, NULL);
- glBindBuffer(GL_ARRAY_BUFFER, buffers[VBO_VERTEX]); glVertexPointer(2, GL_INT, 0, NULL);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- glErrors();
+ backdropGfx->draw();
if (mappreview)
{
@@ -376,8 +329,9 @@ void screen_Display()
//bitmap MUST be (BACKDROP_HACK_WIDTH * BACKDROP_HACK_HEIGHT) for now.
void screen_Upload(const char *newBackDropBmp)
{
- int x1 = 0, x2 = screenWidth, y1 = 0, y2 = screenHeight, scale = 0, w = 0, h = 0;
+ GLfloat x1 = 0, x2 = screenWidth, y1 = 0, y2 = screenHeight;
GLfloat tx = 1, ty = 1;
+ int scale = 0, w = 0, h = 0;
const float aspect = screenWidth / (float)screenHeight, backdropAspect = 4 / (float)3;
if (aspect < backdropAspect)
@@ -395,14 +349,7 @@ void screen_Upload(const char *newBackDropBmp)
if (newBackDropBmp) // preview
{
- pie_SetTexturePage(TEXPAGE_EXTERN);
- glBindTexture(GL_TEXTURE_2D, backDropTexture);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, BACKDROP_HACK_WIDTH, BACKDROP_HACK_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, newBackDropBmp);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ backdropGfx->makeTexture(BACKDROP_HACK_WIDTH, BACKDROP_HACK_HEIGHT, GL_NEAREST, GL_RGB, newBackDropBmp);
int s1 = screenWidth / preview_width;
int s2 = screenHeight / preview_height;
@@ -421,14 +368,8 @@ void screen_Upload(const char *newBackDropBmp)
// Generate coordinates and put them into VBOs
GLfloat texcoords[8] = { 0.0f, 0.0f, tx, 0.0, 0.0f, ty, tx, ty };
- GLint vertices[8] = { x1, y1, x2, y1, x1, y2, x2, y2 };
- glBindBuffer(GL_ARRAY_BUFFER, buffers[VBO_TEXCOORD]);
- glBufferData(GL_ARRAY_BUFFER, sizeof(texcoords), texcoords, GL_STATIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER, buffers[VBO_VERTEX]);
- glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
-
- glErrors();
+ GLfloat vertices[8] = { x1, y1, x2, y1, x1, y2, x2, y2 };
+ backdropGfx->buffers(4, vertices, texcoords);
}
void screen_enableMapPreview(int width, int height, Vector2i *playerpositions)
View
8 lib/ivis_opengl/tex.cpp
@@ -184,14 +184,6 @@ int pie_AddTexPage(iV_Image *s, const char* filename, int slot, int maxTextureSi
return page;
}
-
-void pie_InitSkybox(SDWORD pageNum)
-{
- pie_SetTexturePage(pageNum);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
-}
-
-
/*!
* Turns filename into a pagename if possible
* \param[in,out] filename Filename to pagify
View
2  lib/ivis_opengl/tex.h
@@ -44,8 +44,6 @@ extern int pie_ReplaceTexPage(iV_Image *s, const char *texPage, int maxTextureSi
extern int pie_AddTexPage(iV_Image *s, const char *filename, int slot, int maxTextureSize, bool useMipmaping);
extern void pie_TexInit(void);
-extern void pie_InitSkybox(SDWORD pageNum);
-
extern void pie_MakeTexPageName(char * filename);
extern void pie_MakeTexPageTCMaskName(char * filename);
View
58 lib/sequence/sequence.cpp
@@ -62,6 +62,7 @@
#include "timer.h"
#include "lib/framework/math_ext.h"
#include "lib/ivis_opengl/piestate.h"
+#include "lib/ivis_opengl/pieblitfunc.h"
#include "lib/sound/audio.h"
#include "lib/sound/openal_error.h"
#include "lib/sound/mixer.h"
@@ -146,7 +147,7 @@ static int dropped = 0;
// Screen dimensions
#define NUM_VERTICES 4
-static GLuint buffers[VBO_COUNT];
+static GFX *videoGfx = NULL;
static GLfloat vertices[NUM_VERTICES][2];
static GLfloat Scrnvidpos[3];
@@ -256,7 +257,6 @@ static double getRelativeTime(void)
const GLfloat texture_width = 1024.0f;
const GLfloat texture_height = 1024.0f;
-static GLuint video_texture;
/** Allocates memory to hold the decoded video frame
*/
@@ -268,14 +268,12 @@ static void Allocate_videoFrame(void)
RGBAframe = (uint32_t *)malloc(size);
memset(RGBAframe, 0, size);
- glGenTextures(1, &video_texture);
}
static void deallocateVideoFrame(void)
{
if (RGBAframe)
free(RGBAframe);
- glDeleteTextures(1, &video_texture);
}
#ifndef __BIG_ENDIAN__
@@ -305,12 +303,6 @@ static void video_write(bool update)
const int height_factor = (use_scanlines ? 2 : 1);
yuv_buffer yuv;
- glErrors();
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, video_texture);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
if (update)
{
int rgb_offset = 0;
@@ -378,9 +370,7 @@ static void video_write(bool update)
rgb_offset += video_width;
}
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, video_width,
- video_height * height_factor, GL_RGBA, GL_UNSIGNED_BYTE, RGBAframe);
- glErrors();
+ videoGfx->updateTexture(RGBAframe, video_width, video_height * height_factor);
}
glDisable(GL_DEPTH_TEST);
@@ -389,21 +379,10 @@ static void video_write(bool update)
glPushMatrix();
glTranslatef(Scrnvidpos[0], Scrnvidpos[1], Scrnvidpos[2]);
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glBindBuffer(GL_ARRAY_BUFFER, buffers[VBO_TEXCOORD]); glTexCoordPointer(2, GL_FLOAT, 0, NULL);
- glBindBuffer(GL_ARRAY_BUFFER, buffers[VBO_VERTEX]); glVertexPointer(2, GL_FLOAT, 0, NULL);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
+ videoGfx->draw();
glPopMatrix();
glErrors();
-
- // Make sure the current texture page is reloaded after we are finished
- // Otherwise WZ will think it is still loaded and not load it again
- pie_SetTexturePage(TEXPAGE_NONE);
}
// FIXME: perhaps we should use wz's routine for audio?
@@ -689,21 +668,22 @@ bool seq_Play(const char* filename)
}
/* open video */
- glGenBuffers(VBO_MINIMAL, buffers);
- glErrors();
+ videoGfx = new GFX(GL_TRIANGLE_STRIP, 2);
if (theora_p)
{
if (videodata.ti.frame_width > texture_width || videodata.ti.frame_height > texture_height)
{
debug(LOG_ERROR, "Video size too large, must be below %.gx%.g!",
texture_width, texture_height);
- glDeleteBuffers(VBO_MINIMAL, buffers);
+ delete videoGfx;
+ videoGfx = NULL;
return false;
}
if (videodata.ti.pixelformat != OC_PF_420)
{
debug(LOG_ERROR, "Video not in YUV420 format!");
- glDeleteBuffers(VBO_MINIMAL, buffers);
+ delete videoGfx;
+ videoGfx = NULL;
return false;
}
char *blackframe = (char *)calloc(1, texture_width * texture_height * 4);
@@ -713,27 +693,15 @@ bool seq_Play(const char* filename)
use_scanlines = SCANLINES_OFF;
Allocate_videoFrame();
-
- glBindTexture(GL_TEXTURE_2D, video_texture);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_width, texture_height,
- 0, GL_RGBA, GL_UNSIGNED_BYTE, blackframe);
+ videoGfx->makeTexture(texture_width, texture_height, GL_LINEAR, GL_RGBA, blackframe);
free(blackframe);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
// when using scanlines we need to double the height
const int height_factor = (use_scanlines ? 2 : 1);
const GLfloat vtwidth = (float)videodata.ti.frame_width / texture_width;
const GLfloat vtheight = (float)videodata.ti.frame_height * height_factor / texture_height;
GLfloat texcoords[NUM_VERTICES * 2] = { 0.0f, 0.0f, vtwidth, 0.0f, 0.0f, vtheight, vtwidth, vtheight };
- glBindBuffer(GL_ARRAY_BUFFER, buffers[VBO_TEXCOORD]);
- glBufferData(GL_ARRAY_BUFFER, sizeof(texcoords), texcoords, GL_STATIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER, buffers[VBO_VERTEX]);
- glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- glErrors();
+ videoGfx->buffers(NUM_VERTICES, vertices, texcoords);
}
/* on to the main decode loop. We assume in this example that audio
@@ -939,8 +907,8 @@ void seq_Shutdown()
debug(LOG_VIDEO, "movie is not playing");
return;
}
- glDeleteBuffers(VBO_MINIMAL, buffers);
- glErrors();
+ delete videoGfx;
+ videoGfx = NULL;
if (vorbis_p)
{
View
12 src/display3d.cpp
@@ -145,8 +145,7 @@ bool godMode;
bool showGateways = false;
bool showPath = false;
-/// The name of the texture page used to draw the skybox
-static char skyboxPageName[PATH_MAX] = "page-25";
+// Skybox data
static float wind = 0.0f;
static float windSpeed = 0.0f;
static float skybox_scale = 10000.0f;
@@ -305,11 +304,10 @@ static const int BLUEPRINT_OPACITY=120;
void setSkyBox(const char *page, float mywind, float myscale)
{
- sstrcpy(skyboxPageName, page);
windSpeed = mywind;
wind = 0.0f;
skybox_scale = myscale;
- pie_InitSkybox(iV_GetTexture(skyboxPageName));
+ pie_Skybox_Texture(page);
}
static inline void rotateSomething(int &x, int &y, uint16_t angle)
@@ -1098,7 +1096,8 @@ bool init3DView(void)
bRender3DOnly = false;
- setSkyBox("page-25", 0.0f, 10000.0f);
+ // default skybox, will override in script if not satisfactory
+ setSkyBox("texpages/page-25-sky-arizona.png", 0.0f, 10000.0f);
// distance is not saved, so initialise it now
distance = START_DISTANCE; // distance
@@ -3537,9 +3536,6 @@ static void renderSurroundings(void)
// rotate it
pie_MatRotY(DEG(wind));
- // Set the texture page
- pie_SetTexturePage(iV_GetTexture(skyboxPageName));
-
if(!gamePaused())
{
wind = wrapf(wind + graphicsTimeAdjustedIncrement(windSpeed), 360.0f);
View
18 src/map.cpp
@@ -116,7 +116,7 @@ static void init_tileNames(int type);
/// The different ground types
GROUND_TYPE *psGroundTypes;
int numGroundTypes;
-char *tileset = NULL;
+char *tilesetDir = NULL;
static int numTile_names;
static char *Tile_names = NULL;
#define ARIZONA 1
@@ -239,9 +239,9 @@ static bool mapLoadGroundTypes(void)
pFileData = fileLoadBuffer;
- debug(LOG_TERRAIN, "tileset: %s", tileset);
+ debug(LOG_TERRAIN, "tileset: %s", tilesetDir);
// For Arizona
- if (strcmp(tileset, "texpages/tertilesc1hw") == 0)
+ if (strcmp(tilesetDir, "texpages/tertilesc1hw") == 0)
{
fallback:
init_tileNames(ARIZONA);
@@ -281,7 +281,7 @@ static bool mapLoadGroundTypes(void)
SetDecals("tileset/arizonadecals.txt", "arizona_decals");
}
// for Urban
- else if (strcmp(tileset, "texpages/tertilesc2hw") == 0)
+ else if (strcmp(tilesetDir, "texpages/tertilesc2hw") == 0)
{
init_tileNames(URBAN);
if (!loadFileToBuffer("tileset/tertilesc2hwGtype.txt", pFileData, FILE_LOAD_BUFFER_SIZE, &fileSize))
@@ -320,7 +320,7 @@ static bool mapLoadGroundTypes(void)
SetDecals("tileset/urbandecals.txt", "urban_decals");
}
// for Rockie
- else if (strcmp(tileset, "texpages/tertilesc3hw") == 0)
+ else if (strcmp(tilesetDir, "texpages/tertilesc3hw") == 0)
{
init_tileNames(ROCKIE);
if (!loadFileToBuffer("tileset/tertilesc3hwGtype.txt", pFileData, FILE_LOAD_BUFFER_SIZE, &fileSize))
@@ -361,7 +361,7 @@ static bool mapLoadGroundTypes(void)
// When a map uses something other than the above, we fallback to Arizona
else
{
- debug(LOG_ERROR, "unsupported tileset: %s", tileset);
+ debug(LOG_ERROR, "unsupported tileset: %s", tilesetDir);
debug(LOG_POPUP, "This is a UNSUPPORTED map with a custom tileset.\nDefaulting to tertilesc1hw -- map may look strange!");
// HACK: / FIXME: For now, we just pretend this is a tertilesc1hw map.
goto fallback;
@@ -627,7 +627,7 @@ static bool mapSetGroundTypes(void)
{
MAPTILE *psTile = mapTile(i, j);
- psTile->ground = determineGroundType(i,j,tileset);
+ psTile->ground = determineGroundType(i, j, tilesetDir);
if (hasDecals(i,j))
{
@@ -779,9 +779,9 @@ bool mapLoad(char *filename, bool preview)
mapHeight = height;
// FIXME: the map preview code loads the map without setting the tileset
- if (!tileset)
+ if (!tilesetDir)
{
- tileset = strdup("texpages/tertilesc1hw");
+ tilesetDir = strdup("texpages/tertilesc1hw");
}
// load the ground types
View
3  src/map.h
@@ -119,7 +119,7 @@ extern MAPTILE *psMapTiles;
extern float waterLevel;
extern GROUND_TYPE *psGroundTypes;
extern int numGroundTypes;
-extern char *tileset;
+extern char *tilesetDir;
#define AIR_BLOCKED 0x01 ///< Aircraft cannot pass tile
#define FEATURE_BLOCKED 0x02 ///< Ground units cannot pass tile due to item in the way
@@ -345,7 +345,6 @@ extern MAPTILE *psMapTiles;
extern GROUND_TYPE *psGroundTypes;
extern int numGroundTypes;
-extern char *tileset;
/*
* Usage-Example:
View
15 src/qtscript.cpp
@@ -509,6 +509,21 @@ QScriptEngine *loadPlayerScript(QString path, int player, int difficulty)
}
//== \item[mapName] The name of the current map.
engine->globalObject().setProperty("mapName", game.map, QScriptValue::ReadOnly | QScriptValue::Undeletable);
+ //== \item[baseType] The area name of the map.
+ QString tilesetType("CUSTOM");
+ if (strcmp(tilesetDir, "texpages/tertilesc1hw") == 0)
+ {
+ tilesetType = "ARIZONA";
+ }
+ else if (strcmp(tilesetDir, "texpages/tertilesc2hw") == 0)
+ {
+ tilesetType = "URBAN";
+ }
+ else if (strcmp(tilesetDir, "texpages/tertilesc3hw") == 0)
+ {
+ tilesetType = "ROCKIES";
+ }
+ engine->globalObject().setProperty("tilesetType", tilesetType, QScriptValue::ReadOnly | QScriptValue::Undeletable);
//== \item[baseType] The type of base that the game starts with. It will be one of CAMP_CLEAN, CAMP_BASE or CAMP_WALLS.
engine->globalObject().setProperty("baseType", game.base, QScriptValue::ReadOnly | QScriptValue::Undeletable);
//== \item[alliancesType] The type of alliances permitted in this game. It will be one of NO_ALLIANCES, ALLIANCES or ALLIANCES_TEAMS.
View
12 src/qtscriptfuncs.cpp
@@ -3682,19 +3682,15 @@ static QScriptValue js_setWeather(QScriptContext *context, QScriptEngine *)
return QScriptValue();
}
-//-- \subsection{setSky(texture page, wind speed, skybox scale)}
-//-- Change the skybox. Default values are "page-25", 0.5, and 10000.0. Returns true on success. (3.2+ only)
+//-- \subsection{setSky(texture file, wind speed, skybox scale)}
+//-- Change the skybox. (3.2+ only)
static QScriptValue js_setSky(QScriptContext *context, QScriptEngine *)
{
QString page = context->argument(0).toString();
float wind = context->argument(1).toNumber();
float scale = context->argument(2).toNumber();
- bool found = iV_GetTexture(page.toUtf8().constData()) >= 0;
- if (found)
- {
- setSkyBox(page.toUtf8().constData(), wind, scale);
- }
- return QScriptValue(found);
+ setSkyBox(page.toUtf8().constData(), wind, scale);
+ return QScriptValue();
}
//-- \subsection{hackMarkTiles([label | x, y[, x2, y2]])}
View
21 src/radar.cpp
@@ -162,12 +162,6 @@ bool resizeRadar(void)
radarTexHeight = scrollMaxY - scrollMinY;
radarBufferSize = radarTexWidth * radarTexHeight * sizeof(UDWORD);
radarBuffer = (uint32_t *)malloc(radarBufferSize);
- if (radarBuffer == NULL)
- {
- debug(LOG_FATAL, "Out of memory!");
- abort();
- return false;
- }
memset(radarBuffer, 0, radarBufferSize);
if (rotateRadar)
{
@@ -179,6 +173,8 @@ bool resizeRadar(void)
}
debug(LOG_WZ, "Setting radar zoom to %u", RadarZoom);
radarSize(RadarZoom);
+ pie_SetRadar(-radarWidth/2.0 - 1, -radarHeight/2.0 - 1, radarWidth, radarHeight,
+ radarTexWidth, radarTexHeight, rotateRadar || (RadarZoom % 16 != 0));
return true;
}
@@ -211,6 +207,7 @@ void SetRadarZoom(uint8_t ZoomLevel)
RadarZoom = ZoomLevel;
radarSize(RadarZoom);
frameSkip = 0;
+ resizeRadar();
}
uint8_t GetRadarZoom(void)
@@ -274,14 +271,9 @@ void drawRadar(void)
if (frameSkip <= 0)
{
- bool filter = true;
- if (!rotateRadar)
- {
- filter = RadarZoom % 16 != 0;
- }
DrawRadarTiles();
DrawRadarObjects();
- pie_DownLoadRadar(radarBuffer, radarTexWidth, radarTexHeight, filter);
+ pie_DownLoadRadar(radarBuffer);
frameSkip = RADAR_FRAME_SKIP;
}
frameSkip--;
@@ -299,10 +291,7 @@ void drawRadar(void)
-radarHeight/2.0 - 1,
radarWidth/2.0,
radarHeight/2.0);
- pie_RenderRadar(-radarWidth/2.0 - 1,
- -radarHeight/2.0 - 1,
- radarWidth,
- radarHeight);
+ pie_RenderRadar();
pie_MatBegin();
pie_TRANSLATE(-radarWidth/2 - 1, -radarHeight/2 - 1, 0);
DrawRadarExtras(0, 0, pixSizeH, pixSizeV);
View
4 src/texture.cpp
@@ -120,8 +120,8 @@ bool texLoad(const char *fileName)
ASSERT_OR_RETURN(false, MIPMAP_MAX == TILE_WIDTH && MIPMAP_MAX == TILE_HEIGHT, "Bad tile sizes");
// store the filename so we can later determine which tileset we are using
- if (tileset) free(tileset);
- tileset = strdup(fileName);
+ if (tilesetDir) free(tilesetDir);
+ tilesetDir = strdup(fileName);
// reset defaults
mipmap_max = MIPMAP_MAX;

No commit comments for this range

Something went wrong with that request. Please try again.