| 1 |
/* Emacs style mode select -*- C -*- |
| 2 |
*----------------------------------------------------------------------------- |
| 3 |
* |
| 4 |
* |
| 5 |
* PrBoom: a Doom port merged with LxDoom and LSDLDoom |
| 6 |
* based on BOOM, a modified and improved DOOM engine |
| 7 |
* Copyright 2006 - 2008 G Jackson, Jaakko Kerônen |
| 8 |
* Copyright 2009 - Andrey Budko |
| 9 |
* |
| 10 |
* This program is free software; you can redistribute it and/or |
| 11 |
* modify it under the terms of the GNU General Public License |
| 12 |
* as published by the Free Software Foundation; either version 2 |
| 13 |
* of the License, or (at your option) any later version. |
| 14 |
* |
| 15 |
* This program is distributed in the hope that it will be useful, |
| 16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
* GNU General Public License for more details. |
| 19 |
* |
| 20 |
* You should have received a copy of the GNU General Public License |
| 21 |
* along with this program; if not, write to the Free Software |
| 22 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 23 |
* 02111-1307, USA. |
| 24 |
* |
| 25 |
* DESCRIPTION: Cool automap things |
| 26 |
* |
| 27 |
*--------------------------------------------------------------------- |
| 28 |
*/ |
| 29 |
|
| 30 |
#ifdef HAVE_CONFIG_H |
| 31 |
#include "config.h" |
| 32 |
#endif |
| 33 |
|
| 34 |
#include <math.h> |
| 35 |
|
| 36 |
#include "SDL.h" |
| 37 |
#ifdef HAVE_LIBSDL2_IMAGE |
| 38 |
#include "SDL_image.h" |
| 39 |
#endif |
| 40 |
|
| 41 |
#include "gl_opengl.h" |
| 42 |
#include "gl_intern.h" |
| 43 |
#include "w_wad.h" |
| 44 |
#include "m_misc.h" |
| 45 |
#include "am_map.h" |
| 46 |
#include "lprintf.h" |
| 47 |
#include "dsda/gl/render_scale.h" |
| 48 |
|
| 49 |
am_icon_t am_icons[am_icon_count + 1] = |
| 50 |
{ |
| 51 |
{-1, "M_SHADOW"}, |
| 52 |
|
| 53 |
{-1, "M_ARROW"}, |
| 54 |
{-1, "M_NORMAL"}, |
| 55 |
{-1, "M_HEALTH"}, |
| 56 |
{-1, "M_ARMOUR"}, |
| 57 |
{-1, "M_AMMO"}, |
| 58 |
{-1, "M_KEY"}, |
| 59 |
{-1, "M_POWER"}, |
| 60 |
{-1, "M_WEAP"}, |
| 61 |
|
| 62 |
{-1, "M_ARROW"}, |
| 63 |
{-1, "M_ARROW"}, |
| 64 |
{-1, "M_ARROW"}, |
| 65 |
{-1, "M_MARK"}, |
| 66 |
{-1, "M_NORMAL"}, |
| 67 |
|
| 68 |
{-1, NULL}, |
| 69 |
}; |
| 70 |
|
| 71 |
typedef struct map_nice_thing_s |
| 72 |
{ |
| 73 |
vbo_xy_uv_rgba_t v[4]; |
| 74 |
} PACKEDATTR map_nice_thing_t; |
| 75 |
|
| 76 |
static array_t map_things[am_icon_count]; |
| 77 |
|
| 78 |
void gld_InitMapPics(void) |
| 79 |
{ |
| 80 |
int i, lump; |
| 81 |
|
| 82 |
i = 0; |
| 83 |
while (am_icons[i].name) |
| 84 |
{ |
| 85 |
lump = W_CheckNumForName2(am_icons[i].name, ns_prboom); |
| 86 |
am_icons[i].lumpnum = lump; |
| 87 |
if (lump != LUMP_NOT_FOUND) |
| 88 |
{ |
| 89 |
SDL_Surface *surf = NULL; |
| 90 |
#ifdef HAVE_LIBSDL2_IMAGE |
| 91 |
SDL_Surface *surf_raw; |
| 92 |
|
| 93 |
surf_raw = IMG_Load_RW(SDL_RWFromConstMem(W_LumpByNum(lump), W_LumpLength(lump)), true); |
| 94 |
|
| 95 |
surf = SDL_ConvertSurface(surf_raw, &RGBAFormat, 0); |
| 96 |
SDL_FreeSurface(surf_raw); |
| 97 |
#endif |
| 98 |
|
| 99 |
if (surf) |
| 100 |
{ |
| 101 |
glGenTextures(1, &am_icons[i].tex_id); |
| 102 |
glBindTexture(GL_TEXTURE_2D, am_icons[i].tex_id); |
| 103 |
|
| 104 |
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); |
| 105 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surf->w, surf->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, surf->pixels); |
| 106 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
| 107 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 108 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); |
| 109 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); |
| 110 |
|
| 111 |
SDL_FreeSurface(surf); |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
i++; |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
void gld_AddNiceThing(int type, float x, float y, float radius, float angle, |
| 120 |
unsigned char r, unsigned char g, unsigned char b, unsigned char a) |
| 121 |
{ |
| 122 |
map_nice_thing_t *thing = M_ArrayGetNewItem(&map_things[type], sizeof(thing[0])); |
| 123 |
|
| 124 |
float sina_r = (float)sin(angle) * radius; |
| 125 |
float cosa_r = (float)cos(angle) * radius; |
| 126 |
|
| 127 |
#define MAP_NICE_THING_INIT(index, _x, _y, _u, _v) \ |
| 128 |
{ \ |
| 129 |
thing->v[index].x = _x; \ |
| 130 |
thing->v[index].y = _y; \ |
| 131 |
thing->v[index].u = _u; \ |
| 132 |
thing->v[index].v = _v; \ |
| 133 |
thing->v[index].r = r; \ |
| 134 |
thing->v[index].g = g; \ |
| 135 |
thing->v[index].b = b; \ |
| 136 |
thing->v[index].a = a; \ |
| 137 |
} \ |
| 138 |
|
| 139 |
MAP_NICE_THING_INIT(0, x + sina_r + cosa_r, y - cosa_r + sina_r, 1.0f, 0.0f); |
| 140 |
MAP_NICE_THING_INIT(1, x + sina_r - cosa_r, y - cosa_r - sina_r, 0.0f, 0.0f); |
| 141 |
MAP_NICE_THING_INIT(2, x - sina_r - cosa_r, y + cosa_r - sina_r, 0.0f, 1.0f); |
| 142 |
MAP_NICE_THING_INIT(3, x - sina_r + cosa_r, y + cosa_r + sina_r, 1.0f, 1.0f); |
| 143 |
|
| 144 |
#undef MAP_NICE_THING_INIT |
| 145 |
} |
| 146 |
|
| 147 |
void gld_DrawNiceThings(int fx, int fy, int fw, int fh) |
| 148 |
{ |
| 149 |
int i; |
| 150 |
|
| 151 |
dsda_GLSetScreenSpaceScissor(fx, fy, fw, fh); |
| 152 |
glEnable(GL_SCISSOR_TEST); |
| 153 |
|
| 154 |
glDisable(GL_ALPHA_TEST); |
| 155 |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 156 |
gld_EnableTexture2D(GL_TEXTURE0_ARB, true); |
| 157 |
|
| 158 |
// activate vertex array, texture coord array and color arrays |
| 159 |
glEnableClientState(GL_VERTEX_ARRAY); |
| 160 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 161 |
glEnableClientState(GL_COLOR_ARRAY); |
| 162 |
|
| 163 |
for (i = 0; i < am_icon_count; i++) |
| 164 |
{ |
| 165 |
array_t *things = &map_things[i]; |
| 166 |
|
| 167 |
if (things->count == 0) |
| 168 |
continue; |
| 169 |
|
| 170 |
glBindTexture(GL_TEXTURE_2D, am_icons[i].tex_id); |
| 171 |
|
| 172 |
{ |
| 173 |
map_nice_thing_t *thing = &((map_nice_thing_t*)things->data)[0]; |
| 174 |
|
| 175 |
// activate and specify pointers to arrays |
| 176 |
glVertexPointer(2, GL_FLOAT, sizeof(thing->v[0]), &thing->v[0].x); |
| 177 |
glTexCoordPointer(2, GL_FLOAT, sizeof(thing->v[0]), &thing->v[0].u); |
| 178 |
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(thing->v[0]), &thing->v[0].r); |
| 179 |
|
| 180 |
glDrawArrays(GL_QUADS, 0, things->count * 4); |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
// deactivate vertex array, texture coord array and color arrays |
| 185 |
glDisableClientState(GL_VERTEX_ARRAY); |
| 186 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
| 187 |
glDisableClientState(GL_COLOR_ARRAY); |
| 188 |
|
| 189 |
gld_ResetLastTexture(); |
| 190 |
glDisable(GL_SCISSOR_TEST); |
| 191 |
} |
| 192 |
|
| 193 |
void gld_ClearNiceThings(void) |
| 194 |
{ |
| 195 |
int type; |
| 196 |
|
| 197 |
for (type = 0; type < am_icon_count; type++) |
| 198 |
{ |
| 199 |
M_ArrayClear(&map_things[type]); |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
void gld_DrawMapLines(void) |
| 204 |
{ |
| 205 |
if (map_lines.count > 0) |
| 206 |
{ |
| 207 |
map_point_t *point = (map_point_t*)map_lines.data; |
| 208 |
|
| 209 |
gld_EnableTexture2D(GL_TEXTURE0_ARB, false); |
| 210 |
glEnableClientState(GL_VERTEX_ARRAY); |
| 211 |
glEnableClientState(GL_COLOR_ARRAY); |
| 212 |
|
| 213 |
glVertexPointer(2, GL_FLOAT, sizeof(point[0]), &point->x); |
| 214 |
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(point[0]), &point->r); |
| 215 |
|
| 216 |
glDrawArrays(GL_LINES, 0, map_lines.count * 2); |
| 217 |
|
| 218 |
gld_EnableTexture2D(GL_TEXTURE0_ARB, true); |
| 219 |
glDisableClientState(GL_VERTEX_ARRAY); |
| 220 |
glDisableClientState(GL_COLOR_ARRAY); |
| 221 |
} |
| 222 |
} |