]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_draw.c
fix allocation of 2D shadowmap textures when the first light LOD is
[xonotic/darkplaces.git] / gl_draw.c
index fad253b9f8ab5fbe8ceca78a27ce6e9a9763e204..3fb3bf0887503bfbdb4a4927b0d0e38673e21108 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -780,13 +780,14 @@ void GL_Draw_Init (void)
 
 void _DrawQ_Setup(void)
 {
+       r_viewport_t viewport;
        if (r_refdef.draw2dstage)
                return;
        r_refdef.draw2dstage = true;
        CHECKGLERROR
-       qglViewport(r_refdef.view.x, vid.height - (r_refdef.view.y + r_refdef.view.height), r_refdef.view.width, r_refdef.view.height);CHECKGLERROR
+       R_Viewport_InitOrtho(&viewport, &identitymatrix, r_refdef.view.x, vid.height - r_refdef.view.y - r_refdef.view.height, r_refdef.view.width, r_refdef.view.height, 0, 0, vid_conwidth.integer, vid_conheight.integer, -10, 100, NULL);
+       R_SetViewport(&viewport);
        GL_ColorMask(r_refdef.view.colormask[0], r_refdef.view.colormask[1], r_refdef.view.colormask[2], 1);
-       GL_SetupView_Mode_Ortho(0, 0, vid_conwidth.integer, vid_conheight.integer, -10, 100);
        qglDepthFunc(GL_LEQUAL);CHECKGLERROR
        qglDisable(GL_POLYGON_OFFSET_FILL);CHECKGLERROR
        GL_CullFace(GL_FRONT); // quake is backwards, this culls back faces
@@ -867,6 +868,59 @@ void DrawQ_Pic(float x, float y, cachepic_t *pic, float width, float height, flo
        R_Mesh_Draw(0, 4, 0, 2, NULL, polygonelements, 0, 0);
 }
 
+void DrawQ_RotPic(float x, float y, cachepic_t *pic, float width, float height, float org_x, float org_y, float angle, float red, float green, float blue, float alpha, int flags)
+{
+       float floats[20];
+       float af = DEG2RAD(-angle); // forward
+       float ar = DEG2RAD(-angle + 90); // right
+       float sinaf = sin(af);
+       float cosaf = cos(af);
+       float sinar = sin(ar);
+       float cosar = cos(ar);
+
+       _DrawQ_ProcessDrawFlag(flags);
+       GL_Color(red, green, blue, alpha);
+
+       R_Mesh_VertexPointer(floats, 0, 0);
+       R_Mesh_ColorPointer(NULL, 0, 0);
+       R_Mesh_ResetTextureState();
+       R_SetupGenericShader(pic != NULL);
+       if (pic)
+       {
+               if (width == 0)
+                       width = pic->width;
+               if (height == 0)
+                       height = pic->height;
+               R_Mesh_TexBind(0, R_GetTexture(pic->tex));
+               R_Mesh_TexCoordPointer(0, 2, floats + 12, 0, 0);
+
+               floats[12] = 0.0f;floats[13] = 0.0f;
+               floats[14] = 1.0f;floats[15] = 0.0f;
+               floats[16] = 1.0f;floats[17] = 1.0f;
+               floats[18] = 0.0f;floats[19] = 1.0f;
+       }
+
+       floats[2] = floats[5] = floats[8] = floats[11] = 0;
+
+// top left
+       floats[0] = x - cosaf*org_x - cosar*org_y;
+       floats[1] = y - sinaf*org_x - sinar*org_y;
+
+// top right
+       floats[3] = x + cosaf*(width-org_x) - cosar*org_y;
+       floats[4] = y + sinaf*(width-org_x) - sinar*org_y;
+
+// bottom right
+       floats[6] = x + cosaf*(width-org_x) + cosar*(height-org_y);
+       floats[7] = y + sinaf*(width-org_x) + sinar*(height-org_y);
+
+// bottom left
+       floats[9]  = x - cosaf*org_x + cosar*(height-org_y);
+       floats[10] = y - sinaf*org_x + sinar*(height-org_y);
+
+       R_Mesh_Draw(0, 4, 0, 2, NULL, polygonelements, 0, 0);
+}
+
 void DrawQ_Fill(float x, float y, float width, float height, float red, float green, float blue, float alpha, int flags)
 {
        float floats[12];
@@ -888,7 +942,7 @@ void DrawQ_Fill(float x, float y, float width, float height, float red, float gr
        R_Mesh_Draw(0, 4, 0, 2, NULL, polygonelements, 0, 0);
 }
 
-// color tag printing
+/// color tag printing
 static const vec4_t string_colors[] =
 {
        // Quake3 colors
@@ -945,7 +999,7 @@ float DrawQ_TextWidth_Font_UntilWidth_TrackColors(const char *text, size_t *maxl
        size_t i;
        float x = 0;
        char ch;
-       int current_alpha, tempcolorindex;
+       int tempcolorindex;
 
        if (*maxlen < 1)
                *maxlen = 1<<30;
@@ -957,15 +1011,13 @@ float DrawQ_TextWidth_Font_UntilWidth_TrackColors(const char *text, size_t *maxl
 
        maxwidth /= fnt->scale;
 
-       current_alpha = 0xf;
-
        for (i = 0;i < *maxlen && text[i];i++)
        {
                if (text[i] == ' ')
                {
-                       if(x + fnt->width_of[' '] > maxwidth)
+                       if(x + fnt->width_of[(int) ' '] > maxwidth)
                                break; // oops, can't draw this
-                       x += fnt->width_of[' '];
+                       x += fnt->width_of[(int) ' '];
                        continue;
                }
                if (text[i] == STRING_COLOR_TAG && !ignorecolorcodes && i + 1 < *maxlen)
@@ -976,7 +1028,7 @@ float DrawQ_TextWidth_Font_UntilWidth_TrackColors(const char *text, size_t *maxl
                                colorindex = ch - '0';
                 continue;
                        }
-                       else if (ch == STRING_COLOR_RGB_DEFAULT && i + 3 < *maxlen ) // ^x found
+                       else if (ch == STRING_COLOR_RGB_TAG_CHAR && i + 3 < *maxlen ) // ^x found
                        {
                                // building colorindex...
                                ch = tolower(text[i+1]);
@@ -998,7 +1050,7 @@ float DrawQ_TextWidth_Font_UntilWidth_TrackColors(const char *text, size_t *maxl
                                                else tempcolorindex = 0;
                                                if (tempcolorindex)
                                                {
-                                                       colorindex = tempcolorindex | current_alpha;
+                                                       colorindex = tempcolorindex | 0xf;
                                                        // ...done! now colorindex has rgba codes (1,rrrr,gggg,bbbb,aaaa)
                                                        i+=3;
                                                        continue;
@@ -1006,30 +1058,6 @@ float DrawQ_TextWidth_Font_UntilWidth_TrackColors(const char *text, size_t *maxl
                                        }
                                }
                        }
-                       /*else if (ch == 'a' && i + 1 < *maxlen) // ^a found
-                       {
-                               if (colorindex > 9)
-                               {
-                                       ch = tolower(text[i+1]);
-                                       if (ch <= '9' && ch >= '0') current_alpha = (ch - '0');
-                                       else if (ch >= 'a' && ch <= 'f') current_alpha = (ch - 87);
-                                       else if (ch == '+' && colorindex > 9)
-                                       {
-                                               current_alpha = colorindex & 0xf;
-                                               if (current_alpha < 0xf)
-                                                       current_alpha++;
-                                       }
-                                       else if (ch == '-' && colorindex > 9)
-                                       {
-                                               current_alpha = colorindex & 0xf;
-                                               if (current_alpha > 0)
-                                                       current_alpha--;
-                                       }
-                                       colorindex = ((colorindex >> 4 ) << 4) + current_alpha;
-                               }
-                               i++;
-                               continue;
-                       }*/
                        else if (ch == STRING_COLOR_TAG) // ^^ found, ignore the first ^ and go to print the second
                                i++;
                        i--;
@@ -1060,7 +1088,7 @@ float DrawQ_String_Font(float startx, float starty, const char *text, size_t max
        float texcoord2f[QUADELEMENTS_MAXQUADS*4*2];
        float color4f[QUADELEMENTS_MAXQUADS*4*4];
        int ch;
-       int current_alpha, tempcolorindex;
+       int tempcolorindex;
 
        int tw, th;
        tw = R_TextureWidth(fnt->tex);
@@ -1094,7 +1122,7 @@ float DrawQ_String_Font(float startx, float starty, const char *text, size_t max
                else
                        colorindex = *outcolor;
 
-               DrawQ_GetTextColor(color, colorindex, basered, basegreen, baseblue, basealpha, shadow);
+               DrawQ_GetTextColor(color, colorindex, basered, basegreen, baseblue, basealpha, shadow != 0);
 
                x = startx;
                y = starty;
@@ -1103,12 +1131,11 @@ float DrawQ_String_Font(float startx, float starty, const char *text, size_t max
                        x += r_textshadow.value;
                        y += r_textshadow.value;
                }
-               current_alpha = 0xf;
                for (i = 0;i < maxlen && text[i];i++)
                {
                        if (text[i] == ' ')
                        {
-                               x += fnt->width_of[' '] * w;
+                               x += fnt->width_of[(int) ' '] * w;
                                continue;
                        }
                        if (text[i] == STRING_COLOR_TAG && !ignorecolorcodes && i + 1 < maxlen)
@@ -1117,10 +1144,10 @@ float DrawQ_String_Font(float startx, float starty, const char *text, size_t max
                                if (ch <= '9' && ch >= '0') // ^[0-9] found
                                {
                                        colorindex = ch - '0';
-                                       DrawQ_GetTextColor(color, colorindex, basered, basegreen, baseblue, basealpha, shadow);
+                                       DrawQ_GetTextColor(color, colorindex, basered, basegreen, baseblue, basealpha, shadow != 0);
                                        continue;
                                }
-                               else if (ch == STRING_COLOR_RGB_DEFAULT && i+3 < maxlen ) // ^x found
+                               else if (ch == STRING_COLOR_RGB_TAG_CHAR && i+3 < maxlen ) // ^x found
                                {
                                        // building colorindex...
                                        ch = tolower(text[i+1]);
@@ -1142,42 +1169,16 @@ float DrawQ_String_Font(float startx, float starty, const char *text, size_t max
                                                        else tempcolorindex = 0;
                                                        if (tempcolorindex)
                                                        {
-                                                               colorindex = tempcolorindex | current_alpha;
+                                                               colorindex = tempcolorindex | 0xf;
                                                                // ...done! now colorindex has rgba codes (1,rrrr,gggg,bbbb,aaaa)
                                                                //Con_Printf("^1colorindex:^7 %x\n", colorindex);
-                                                               DrawQ_GetTextColor(color, colorindex, basered, basegreen, baseblue, basealpha, shadow);
+                                                               DrawQ_GetTextColor(color, colorindex, basered, basegreen, baseblue, basealpha, shadow != 0);
                                                                i+=3;
                                                                continue;
                                                        }
                                                }
                                        }
                                }
-                               /*else if (ch == 'a' && i+1 < maxlen ) // ^a found
-                               {
-                                       if (colorindex > 9) // colorindex is a RGB color
-                                       {
-                                               ch = tolower(text[i+1]);
-                                               if (ch <= '9' && ch >= '0') current_alpha = (ch - '0');
-                                               else if (ch >= 'a' && ch <= 'f') current_alpha = (ch - 87);
-                                               else if (ch == '+' && colorindex > 9)
-                                               {
-                                                       current_alpha = colorindex & 0xf;
-                                                       if (current_alpha < 0xf)
-                                                               current_alpha++;
-                                               }
-                                               else if (ch == '-' && colorindex > 9)
-                                               {
-                                                       current_alpha = colorindex & 0xf;
-                                                       if (current_alpha > 0)
-                                                               current_alpha--;
-                                               }
-                                               colorindex = ((colorindex >> 4 ) << 4) + current_alpha;
-                                               //Con_Printf("^1colorindex:^7 %x\n", colorindex);
-                                               DrawQ_GetTextColor(color, colorindex, basered, basegreen, baseblue, basealpha, shadow);
-                                       }
-                                       i++;
-                                       continue;
-                               }*/
                                else if (ch == STRING_COLOR_TAG)
                                        i++;
                                i--;
@@ -1380,11 +1381,16 @@ void DrawQ_Line (float width, float x1, float y1, float x2, float y2, float r, f
 
 void DrawQ_SetClipArea(float x, float y, float width, float height)
 {
+       int ix, iy, iw, ih;
        _DrawQ_Setup();
 
        // We have to convert the con coords into real coords
        // OGL uses top to bottom
-       GL_Scissor((int)(x * ((float)vid.width / vid_conwidth.integer)), (int)(y * ((float) vid.height / vid_conheight.integer)), (int)(width * ((float)vid.width / vid_conwidth.integer)), (int)(height * ((float)vid.height / vid_conheight.integer)));
+       ix = (int)(0.5 + x * ((float)vid.width / vid_conwidth.integer));
+       iy = (int)(0.5 + y * ((float) vid.height / vid_conheight.integer));
+       iw = (int)(width * ((float)vid.width / vid_conwidth.integer));
+       ih = (int)(height * ((float)vid.height / vid_conheight.integer));
+       GL_Scissor(ix, vid.height - iy - ih, iw, ih);
 
        GL_ScissorTest(true);
 }