Forum

hud image scaling

Discuss programming topics for the various GPL'd game engine sources.

Moderator: InsideQC Admins

hud image scaling

Postby Hazematman » Mon Aug 02, 2010 4:13 am

when I run my game in 640x400 it looks like this:

Image

but when I run my game in 1024x768 the hud looks like this:

Image

the image size is 640x400.

is there someway I can tell it to scale the image to the screen size or will I have to make several images and tell it to use that one if the screen size is set to x?
User avatar
Hazematman
 
Posts: 54
Joined: Thu Jul 15, 2010 1:58 am
Location: Canada

Postby Spike » Mon Aug 02, 2010 8:56 am

make your own Draw_pic. Scale to vid.width+vid.height.

or just enforce -conwidth on the commandline, but that's evil
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby Hazematman » Mon Aug 02, 2010 2:40 pm

how exactly would I do the scaling? for my draw pic I have this
Code: Select all
Draw_TransPic(0, 0, Draw_CachePic("gfx/hud.lmp"));


so I'm guessing I would have to do something like this:
Code: Select all
Draw_TransPic(0, 0, Draw_CachePic("gfx/hud.lmp"));
Scale("gfx/hud.imp")vid.width+vid.height;


but that is not working.
User avatar
Hazematman
 
Posts: 54
Joined: Thu Jul 15, 2010 1:58 am
Location: Canada

Postby Spike » Mon Aug 02, 2010 2:59 pm

Draw_ScaleTransPic(0, 0, vid.width, vid.height, Draw_CachePic("gfx/hud.lmp"));

And then write a Draw_ScaleTransPic function - you will need to modify gl_draw.c, obviously...
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby mh » Mon Aug 02, 2010 3:15 pm

Alternatively set pic.width = vid.vidth and pic.height = vid.height before drawing it. But both methods work fine.

I see you're getting a case of the pink fringe attack too so you might want to set palette index 255 to all 0.

Finally, using image sizes that aren't powers of 2 is not really healthy for GLQuake. It will kind of resample them, but you'll get better quality resizing it yourself in an image editor. 512x512 should be perfectly good enough for this pic.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Postby Hazematman » Mon Aug 02, 2010 3:33 pm

I'm no expert at the quake source code but to make a scale_pic function I would copy the draw_pic function in gl_draw.c:


Code: Select all
/*
=============
Draw_Pic
=============
*/
void Draw_Pic (int x, int y, qpic_t *pic)
{
   byte         *dest, *source;
   unsigned short   *pusdest;
   int            v, u;
   glpic_t         *gl;

   if (scrap_dirty)
      Scrap_Upload ();
   gl = (glpic_t *)pic->data;
   glColor4f (1,1,1,1);
   GL_Bind (gl->texnum);
   glBegin (GL_QUADS);
   glTexCoord2f (gl->sl, gl->tl);
   glVertex2f (x, y);
   glTexCoord2f (gl->sh, gl->tl);
   glVertex2f (x+pic->width, y);
   glTexCoord2f (gl->sh, gl->th);
   glVertex2f (x+pic->width, y+pic->height);
   glTexCoord2f (gl->sl, gl->th);
   glVertex2f (x, y+pic->height);
   glEnd ();
}


but what would I add to it, to make it scale?
User avatar
Hazematman
 
Posts: 54
Joined: Thu Jul 15, 2010 1:58 am
Location: Canada

Postby r00k » Mon Aug 02, 2010 10:42 pm

replace the x+pic->width and y+pic->height
with x+width and y+height and create the variables
int width and int height in your parameters like

Draw_Scale_Pic (int x, int y, int width, int height, qpic_t *pic)

OR

If you really wanna get cut and pastey

Code: Select all
void GL_FullscreenQuad(int texture, float alpha)
{
   int vwidth = 1, vheight = 1;
   float vs, vt;

   while (vwidth < glwidth)
   {
      vwidth *= 2;
   }
   while (vheight < glheight)
   {
      vheight *= 2;
   }

   glViewport (glx, gly, glwidth, glheight);

   GL_Bind(texture);

   // go 2d
   glMatrixMode(GL_PROJECTION);
   glPushMatrix();
   glLoadIdentity ();
   glOrtho  (0, glwidth, 0, glheight, -99999, 99999);
   glMatrixMode(GL_MODELVIEW);
   glPushMatrix();
   glLoadIdentity ();

   vs = ((float)glwidth / vwidth);
   vt = ((float)glheight / vheight) ;

   glDisable (GL_DEPTH_TEST);
   glDisable (GL_CULL_FACE);
   glDisable (GL_ALPHA_TEST);
   glEnable (GL_BLEND);
   
   glAlphaFunc(GL_GREATER,0.000f);
   glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR);
   glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
   glDepthMask(0);

   glColor4f(1, 1, 1, alpha);

   glBegin(GL_QUADS);
      glTexCoord2f(0, 0);
      glVertex2f(0, 0);
      glTexCoord2f(vs , 0);
      glVertex2f(glwidth, 0);
      glTexCoord2f(vs , vt);
      glVertex2f(glwidth, glheight);
      glTexCoord2f(0, vt);
      glVertex2f(0, glheight);
   glEnd();

   glEnable(GL_DEPTH_TEST);
   glDepthMask(1);
   glDisable(GL_ALPHA_TEST);
   glAlphaFunc(GL_GREATER,0.666f);
   glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
   glColor3f (1,1,1);   
    glDisable (GL_BLEND);   
    glEnable (GL_TEXTURE_2D);   
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);   
   //?glEnable(GL_CULL_FACE);
   glMatrixMode(GL_PROJECTION);
   glPopMatrix();      
   glMatrixMode(GL_MODELVIEW);
   glPopMatrix();      
}
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Postby Baker » Tue Aug 03, 2010 2:23 am

Do it the "right" way and open up gfx.wad with something like fimg and create a 320x200 compatible quake paletted version of your "replacement" image.

Then it will scale properly at any resolution.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am


Return to Engine Programming

Who is online

Users browsing this forum: No registered users and 1 guest