44typedef struct char_arrays_s {
57#define MAX_BATCH_ENTRIES 512
60typedef struct batch_arrays_s {
70#define MAX_BBOX_ENTRIES 256
72typedef struct bbox_arrays_s {
87 Com_Printf(
"Could not find shadow image in game pics/sfx directory!\n");
103 if ((num & 127) ==
' ')
112 int row = (
int) num >> 4;
113 int col = (
int) num & 15;
116 float frow = row * 0.0625;
117 float fcol = col * 0.0625;
190 const float nx = x *
viddef.rx;
191 const float ny = y *
viddef.ry;
192 const float nw = w *
viddef.rx;
193 const float nh = h *
viddef.ry;
194 const int r = color[0] * 255.0;
195 const int g = color[1] * 255.0;
196 const int b = color[2] * 255.0;
197 const int a = color[3] * 255.0;
198 const uint32_t c =
LittleLong((r << 0) + (g << 8) + (b << 16) + (a << 24));
274 int scaledWidth, scaledHeight;
276#ifdef GL_VERSION_ES_CM_1_0
287 for (
unsigned const*
i = frame, *
const end =
i + scaledHeight * scaledWidth;
i != end; ++
i) {
288 if ((*
i & 0xFF000000U) != 0xFF000000U) {
294 if (scaledWidth != width || scaledHeight != height) {
296 R_ScaleTexture(frame, width, height, scaled, scaledWidth, scaledHeight);
303 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, scaledWidth, scaledHeight, GL_RGBA, GL_UNSIGNED_BYTE, scaled);
310 glTexImage2D(GL_TEXTURE_2D, 0, samples, scaledWidth, scaledHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, scaled);
360 glVertexPointer(2, GL_FLOAT, 0, verts);
361 R_BindArray(GL_TEXTURE_COORD_ARRAY, GL_FLOAT, texcoords);
363 if (image !=
nullptr)
366 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
390void R_DrawRect (
int x,
int y,
int w,
int h,
const vec4_t color,
float lineWidth,
int pattern)
392 const float nx = x *
viddef.rx;
393 const float ny = y *
viddef.ry;
394 const float nw = w *
viddef.rx;
395 const float nh = h *
viddef.ry;
396 const vec2_t points[] = { { nx, ny }, { nx + nw, ny }, { nx + nw, ny + nh }, { nx, ny + nh } };
400 glDisable(GL_TEXTURE_2D);
401 glLineWidth(lineWidth);
402#ifndef GL_VERSION_ES_CM_1_0
403 glLineStipple(2, pattern);
404 glEnable(GL_LINE_STIPPLE);
407 glVertexPointer(2, GL_FLOAT, 0, points);
408 glDrawArrays(GL_LINE_LOOP, 0, 4);
413 glEnable(GL_TEXTURE_2D);
415#ifndef GL_VERSION_ES_CM_1_0
416 glDisable(GL_LINE_STIPPLE);
425 const size_t steps =
lengthof(points);
427 glEnable(GL_LINE_SMOOTH);
428 glLineWidth(thickness);
432 for (
unsigned int i = 0;
i < steps;
i++) {
433 const float a = 2.0f *
M_PI * (float)
i / (
float) steps;
438 glDrawArrays(GL_LINE_LOOP, 0, steps);
446 glDisable(GL_LINE_SMOOTH);
449#define MAX_LINEVERTS 256
458 glVertexPointer(2, GL_SHORT, 0,
r_state.vertex_array_2d);
460 for (
int i = 0;
i < points * 2;
i += 2) {
465 glDisable(GL_TEXTURE_2D);
466 glDrawArrays(
mode, 0, points);
467 glEnable(GL_TEXTURE_2D);
468 glVertexPointer(3, GL_FLOAT, 0,
r_state.vertex_array_3d);
497 glLineWidth(thickness);
521#define MAX_CLIPRECT 16
535 out->
x = (a->
x > b->
x) ? a->
x : b->
x;
536 out->
y = (a->
y > b->
y) ? a->
y : b->
y;
572 glEnable(GL_SCISSOR_TEST);
584 glDisable(GL_SCISSOR_TEST);
598 const float nx = x *
viddef.rx;
599 const float ny = y *
viddef.ry;
600 const int nwidth = width *
viddef.rx;
601 const int nheight = height *
viddef.ry;
602 const GLboolean hasDepthTest = glIsEnabled(GL_DEPTH_TEST);
603 const GLfloat bigZ = 2000.0f;
604 const vec3_t points [] = { { nx, ny, bigZ }, { nx + nwidth, ny, bigZ }, { nx + nwidth, ny + nheight, bigZ }, { nx, ny + nheight, bigZ } };
607 glGetIntegerv(GL_DEPTH_FUNC, &depthFunc);
610 glEnable(GL_DEPTH_TEST);
611 glDepthFunc(GL_ALWAYS);
612 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
615 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
620 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
622 glDisable(GL_DEPTH_TEST);
623 glDepthFunc(depthFunc);
633 for (
int i = 0;
i < 8;
i++) {
634 bbox[
i][0] = (
i & 1) ? mins[0] : maxs[0];
635 bbox[
i][1] = (
i & 2) ? mins[1] : maxs[1];
636 bbox[
i][2] = (
i & 4) ? mins[2] : maxs[2];
642 const int step = 3 * 8;
644 const GLushort indexes[] = { 2, 1, 0, 1, 4, 5, 1, 7, 3, 2, 7, 6, 2, 4, 0 };
645 const GLushort indexes2[] = { 4, 6, 7 };
650 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
654 for (
int i = 0;
i < bboxes;
i++) {
658 glDrawElements(GL_TRIANGLE_FAN, 15, GL_UNSIGNED_SHORT, indexes);
660 glDrawElements(GL_TRIANGLE_FAN, 3, GL_UNSIGNED_SHORT, indexes2);
665 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
680 for (
int i = 0;
i < 8;
i++) {
693 const GLushort indexes[] = { 2, 1, 0, 1, 4, 5, 1, 7, 3, 2, 7, 6, 2, 4, 0 };
694 const GLushort indexes2[] = { 4, 6, 7 };
698 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
702 glDrawElements(GL_TRIANGLE_STRIP, 15, GL_UNSIGNED_SHORT, indexes);
704 glDrawElements(GL_TRIANGLE_STRIP, 3, GL_UNSIGNED_SHORT, indexes2);
707 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
716 const GLfloat texcoords[] = { 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, };
718 { a0[0], a0[1], a0[2] }, { a0[0], a0[1], a1[2] }, { a1[0], a0[1], a1[2] }, { a1[0], a0[1], a0[2] },
719 { a1[0], a1[1], a0[2] }, { a1[0], a1[1], a1[2] }, { a0[0], a1[1], a1[2] }, { a0[0], a1[1], a0[2] },
720 { a0[0], a0[1], a0[2] }, { a0[0], a0[1], a1[2] }, { a1[0], a0[1], a1[2] }, { a1[0], a0[1], a0[2] },
721 { a1[0], a1[1], a0[2] }, { a1[0], a1[1], a1[2] }, { a0[0], a1[1], a1[2] }, { a0[0], a1[1], a0[2] } };
722 const GLushort indexes[] = { 0, 1, 2, 1, 2, 3, 4, 5, 6, 6, 7, 4, 2 + 8, 3 + 8, 4 + 8, 2 + 8, 5 + 8, 4 + 8, 6 + 8, 7 + 8,
723 0 + 8, 0 + 8, 1 + 8, 6 + 8, };
725 R_BindArray(GL_TEXTURE_COORD_ARRAY, GL_FLOAT, texcoords);
729 glDrawElements(GL_TRIANGLES, 8 * 3, GL_UNSIGNED_SHORT, indexes);
memPool_t * vid_imagePool
void R_Color(const vec4_t rgba)
Change the color to given value.
void Com_Error(int code, const char *fmt,...)
void Com_Printf(const char *const fmt,...)
void glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *texels)
void glTexParameterf(GLenum target, GLenum pname, GLfloat param)
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
#define Mem_PoolAllocTypeN(type, n, pool)
void R_DrawTexture(int texnum, int x, int y, int w, int h)
Bind and draw a texture.
void R_DrawBoundingBoxes(void)
static image_t * draw_chars
void R_DrawFill(int x, int y, int w, int h, const vec4_t color)
Fills a box of pixels with a single color.
void R_DrawLine(int *verts, float thickness)
Draws one line with only one start and one end point.
void R_DrawChar(int x, int y, int num, uint32_t color)
Draws one 8*8 graphics character with 0 being transparent. It can be clipped to the top of the screen...
void R_DrawPolygon(int points, int *verts)
static bbox_arrays_t r_bbox_array
static char_arrays_t r_char_arrays
void R_DrawLineStrip(int points, int *verts)
2 dimensional line strip
void R_DrawImage(float x, float y, const image_t *image)
Draws an image or parts of it.
void R_DrawStretchImage(float x, float y, int w, int h, const image_t *image)
static void R_RectIntersection(const rect_t *a, const rect_t *b, rect_t *out)
Compute the intersection of 2 rect.
void R_DrawBoundingBoxBatched(const AABB &absbox)
void R_DrawLineLoop(int points, int *verts)
void R_PushClipRect(int x, int y, int width, int height)
Force to draw only on a rect.
static void R_ComputeBoundingBox(const vec3_t mins, const vec3_t maxs, vec3_t bbox[8])
Compute the bounding box for an entity out of the mins, maxs.
void R_DrawTexturedBox(const vec3_t a0, const vec3_t a1)
Draws the textured box, the caller should bind the texture.
static int currentClipRect
void R_DrawInitLocal(void)
Loads some textures and init the 3d globe.
void R_DrawBoundingBox(const AABB &absBox)
Draws the model bounding box.
void R_DrawCircle(float radius, const vec4_t color, float thickness, const vec3_t shift)
const image_t * R_DrawImageArray(const vec2_t texcoords[4], const vec2_t verts[4], const image_t *image)
static void R_Draw2DArray(int points, int *verts, GLenum mode)
int R_UploadData(const char *name, unsigned *frame, int width, int height)
Uploads image data.
void R_CleanupDepthBuffer(int x, int y, int width, int height)
"Clean up" the depth buffer into a rect
#define MAX_BATCH_ENTRIES
void R_DrawRect(int x, int y, int w, int h, const vec4_t color, float lineWidth, int pattern)
Draws a rect to the screen. Also has support for stippled rendering of the rect.
static batch_arrays_t r_fill_arrays
static rect_t clipRect[MAX_CLIPRECT]
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
QGL_EXTERN GLboolean(APIENTRY *qglIsRenderbufferEXT)(GLuint)
void R_DrawArrays(GLint first, GLsizei count)
QGL_EXTERN const GLuint *QGL_EXTERN GLuint *QGL_EXTERN GLenum
image_t * R_FindImage(const char *pname, imagetype_t type)
Finds or loads the given image.
void R_GetScaledTextureSize(int width, int height, int *scaledWidth, int *scaledHeight)
Calculates the texture size that should be used to upload the texture data.
void R_ScaleTexture(const unsigned *in, int inwidth, int inheight, unsigned *out, int outwidth, int outheight)
local graphics definitions
static ipos3_t shift
The shift array is used for random map assemblies (RMA) to shift the mins/maxs and stuff like that.
Functions to generate and render spheres.
void R_EnableTexture(gltexunit_t *texunit, bool enable)
void R_BindDefaultArray(GLenum target)
Binds the appropriate shared vertex array to the specified target.
const vec2_t default_texcoords[4]
void R_EnableColorArray(bool enable)
void R_BindArray(GLenum target, GLenum type, const void *array)
#define R_BindTexture(tn)
array to store batched vertices and colors per frame
GLbyte colors[MAX_BATCH_ENTRIES *4 *4]
GLshort verts[MAX_BATCH_ENTRIES *4 *2]
float bboxes[3 *8 *MAX_BBOX_ENTRIES]
Characters are batched per frame and drawn in one shot accumulate coordinates and colors as vertex ar...
GLshort verts[MAX_CHARS *4 *2]
GLfloat texcoords[MAX_CHARS *4 *2]
GLbyte colors[MAX_CHARS *4 *4]
#define Vector2FromInt(x, y)
#define VectorCopy(src, dest)
#define VectorSet(v, x, y, z)