Skip to content

Commit

Permalink
Changed API: Viewwindow is now specified in viewport coordinates (for…
Browse files Browse the repository at this point in the history
…merly fixed 320x200). Note that game-side we still use the fixed coordinate space for convenience and scale up when calling R_SetViewWindow.

Changed API: Before calling game-side drawing routines the engine now configures the orthographic projection in the viewport coordinate space (formerly fixed 320x200). It is now the games responsibility to scale the coordinate space if/as required.
Changed All games: Removed ccmd viewsize as its now unnecessary as the cvar view-size can be changed directly from the console.
Changed All games: Improved animation between view sizes to include HUD display modes.
Changed All games: Aspect correct drawing of the crosshair.
  • Loading branch information
danij-deng committed Apr 25, 2010
1 parent 6a53824 commit 10c8623
Show file tree
Hide file tree
Showing 32 changed files with 226 additions and 496 deletions.
10 changes: 0 additions & 10 deletions doomsday/engine/portable/src/dd_loop.c
Expand Up @@ -214,22 +214,12 @@ void DD_DrawAndBlit(void)

R_RenderViewPorts();

// Set up the basic 320x200 legacy projection for the game.
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, 320, 200, 0, -1, 1);

// Draw any over/outside view window game graphics (e.g. fullscreen
// menus and other displays).
if(gx.G_Drawer2 && !(UI_IsActive() && UI_Alpha() >= 1.0))
{
gx.G_Drawer2();
}

// Restore the projection mode that was previously in effect.
glMatrixMode(GL_PROJECTION);
glPopMatrix();
}

if(Con_TransitionInProgress())
Expand Down
66 changes: 23 additions & 43 deletions doomsday/engine/portable/src/gl_main.c
Expand Up @@ -741,29 +741,12 @@ void GL_SwitchTo3DState(boolean push_state, viewport_t* port)
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);

#if 0
viewpx = viewwindowx * theWindow->width / 320, viewpy =
viewwindowy * theWindow->height / 200;
// Set the viewport.
if(viewheight != SCREENHEIGHT)
{
viewpw = viewwidth * theWindow->width / 320;
viewph = viewheight * theWindow->height / 200 + 1;
glViewport(viewpx, FLIP(viewpy + viewph - 1), viewpw, viewph);
}
else
{
viewpw = theWindow->width;
viewph = theWindow->height;
}
#endif

memcpy(&currentView, port, sizeof(currentView));

viewpx = port->x + viewwindowx / 320.0f * port->width;
viewpy = port->y + viewwindowy / 200.0f * port->height;
viewpw = port->width * viewwidth / 320.0f;
viewph = port->height * viewheight / 200.0f;
viewpx = port->x + MIN_OF(viewwindowx, port->width);
viewpy = port->y + MIN_OF(viewwindowy, port->height);
viewpw = MIN_OF(port->width, viewwidth);
viewph = MIN_OF(port->height, viewheight);
glViewport(viewpx, FLIP(viewpy + viewph - 1), viewpw, viewph);

// The 3D projection matrix.
Expand All @@ -789,7 +772,7 @@ void GL_Restore2DState(int step, viewport_t* port)
{
case 1: // After Restore Step 1 normal player sprites are rendered.
{
int height = (SCREENWIDTH * viewheight) / viewwidth;
int height = (float)(port->width * viewheight / viewwidth) / port->height * SCREENHEIGHT;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
Expand All @@ -810,23 +793,23 @@ void GL_Restore2DState(int step, viewport_t* port)
* corrected coordinate space at 4:3, aligned vertically to
* the bottom and centered horizontally in the window.
*/
glOrtho(0, port->width, port->height, 0, -1, 1);
glTranslatef(port->width/2, port->height, 0);

if(port->width >= port->height)
glScalef((float)port->height/SCREENHEIGHT, (float)port->height/SCREENHEIGHT, 1);
else
glScalef((float)port->width/SCREENWIDTH, (float)port->width/SCREENWIDTH, 1);

// Special case: viewport height is greater than width.
// Apply an additional scaling factor to prevent player sprites looking too small.
if(port->height > port->width)
{
float extraScale = (((float)port->height*2)/port->width) / 2;
glScalef(extraScale, extraScale, 1);
}

glTranslatef(-(SCREENWIDTH/2), -SCREENHEIGHT, 0);
glOrtho(0, port->width, port->height, 0, -1, 1);
glTranslatef(port->width/2, port->height, 0);

if(port->width >= port->height)
glScalef((float)port->height/SCREENHEIGHT, (float)port->height/SCREENHEIGHT, 1);
else
glScalef((float)port->width/SCREENWIDTH, (float)port->width/SCREENWIDTH, 1);

// Special case: viewport height is greater than width.
// Apply an additional scaling factor to prevent player sprites looking too small.
if(port->height > port->width)
{
float extraScale = (((float)port->height*2)/port->width) / 2;
glScalef(extraScale, extraScale, 1);
}

glTranslatef(-(SCREENWIDTH/2), -SCREENHEIGHT, 0);
glScalef(1, (float)SCREENHEIGHT/height, 1);
}

Expand All @@ -838,12 +821,9 @@ void GL_Restore2DState(int step, viewport_t* port)
glDisable(GL_DEPTH_TEST);
break;
}
case 2: // After Restore Step 2 nothing special happens.
case 2: // After Restore Step 2 we're back in 2D rendering mode.
glViewport(currentView.x, FLIP(currentView.y + currentView.height - 1),
currentView.width, currentView.height);
break;

case 3: // After Restore Step 3 we're back in 2D rendering mode.
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
Expand Down
58 changes: 13 additions & 45 deletions doomsday/engine/portable/src/r_draw.c
Expand Up @@ -128,48 +128,19 @@ static void drawPatchTiled(lumpnum_t lump, int x, int y, int w, int h)
*/
void R_DrawViewBorder(void)
{
int viewX, viewY, viewW, viewH, border;
int border;
const viewport_t* port;
float xScale, yScale;
material_t* mat;

if(viewwidth == 320 && viewheight == 200)
return;

port = R_CurrentViewPort();
assert(port);

xScale = (float) port->width / SCREENWIDTH;
yScale = (float) port->height / SCREENHEIGHT;

viewX = viewwindowx * xScale;
viewY = viewwindowy * yScale;
viewW = viewwidth * xScale;
viewH = viewheight * yScale;

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

/**
* Use an orthographic projection in native screenspace. Then
* translate and scale the projection to produce an aspect
* corrected coordinate space at 4:3.
*/
glOrtho(0, port->width, port->height, 0, -1, 1);
if(viewwidth == port->width && viewheight == port->height)
return;

glMatrixMode(GL_TEXTURE);
glPushMatrix();

// Correct viewport aspect ratio?
if(port->width < SCREENWIDTH || port->height < SCREENHEIGHT)
{
if(port->width >= port->height)
glScalef((float)port->height/SCREENHEIGHT, (float)port->height/SCREENHEIGHT, 1);
else
glScalef((float)port->width/SCREENWIDTH, (float)port->width/SCREENWIDTH, 1);
}

// Scale from viewport space to fixed 320x200 space.
if(port->width >= port->height)
{
Expand All @@ -190,29 +161,26 @@ void R_DrawViewBorder(void)
{
GL_SetMaterial(mat);
GL_DrawCutRectTiled(0, 0, port->width, port->height, mat->width, mat->height, 0, 0,
viewX - border, viewY - border,
viewW + 2 * border, viewH + 2 * border);
viewwindowx - border, viewwindowy - border,
viewwidth + 2 * border, viewheight + 2 * border);
}

if(border != 0)
{
drawPatchTiled(borderPatchLumps[BG_TOP], viewX, viewY - border, viewW, border);
drawPatchTiled(borderPatchLumps[BG_BOTTOM], viewX, viewY + viewH , viewW, border);
drawPatchTiled(borderPatchLumps[BG_LEFT], viewX - border, viewY, border, viewH);
drawPatchTiled(borderPatchLumps[BG_RIGHT], viewX + viewW, viewY, border, viewH);
drawPatchTiled(borderPatchLumps[BG_TOP], viewwindowx, viewwindowy - border, viewwidth, border);
drawPatchTiled(borderPatchLumps[BG_BOTTOM], viewwindowx, viewwindowy + viewheight , viewwidth, border);
drawPatchTiled(borderPatchLumps[BG_LEFT], viewwindowx - border, viewwindowy, border, viewheight);
drawPatchTiled(borderPatchLumps[BG_RIGHT], viewwindowx + viewwidth, viewwindowy, border, viewheight);
}

glMatrixMode(GL_TEXTURE);
glPopMatrix();

if(border != 0)
{
drawPatch(borderPatchLumps[BG_TOPLEFT], viewX - border, viewY - border, border, border);
drawPatch(borderPatchLumps[BG_TOPRIGHT], viewX + viewW, viewY - border, border, border);
drawPatch(borderPatchLumps[BG_BOTTOMRIGHT], viewX + viewW, viewY + viewH, border, border);
drawPatch(borderPatchLumps[BG_BOTTOMLEFT], viewX - border, viewY + viewH, border, border);
drawPatch(borderPatchLumps[BG_TOPLEFT], viewwindowx - border, viewwindowy - border, border, border);
drawPatch(borderPatchLumps[BG_TOPRIGHT], viewwindowx + viewwidth, viewwindowy - border, border, border);
drawPatch(borderPatchLumps[BG_BOTTOMRIGHT], viewwindowx + viewwidth, viewwindowy + viewheight, border, border);
drawPatch(borderPatchLumps[BG_BOTTOMLEFT], viewwindowx - border, viewwindowy + viewheight, border, border);
}

glMatrixMode(GL_PROJECTION);
glPopMatrix();
}
28 changes: 20 additions & 8 deletions doomsday/engine/portable/src/r_main.c
Expand Up @@ -862,22 +862,23 @@ void R_RenderPlayerView(int num)
if(renderWireframe)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

// Fullscreen viewport.
GL_Restore2DState(2, currentPort);
// Do we need to render any 3D psprites?
if(psp3d)
{
GL_SwitchTo3DState(false, currentPort);
Rend_Draw3DPlayerSprites();
GL_Restore2DState(2, currentPort); // Restore viewport.
}
// Original matrices and state: back to normal 2D.
GL_Restore2DState(3, currentPort);

// Restore fullscreen viewport, original matrices and state: back to normal 2D.
GL_Restore2DState(2, currentPort);

// Back from wireframe mode?
if(renderWireframe)
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

// The colored filter.
GL_DrawFilter();

// Now we can show the viewPlayer's mobj again.
if(!(player->shared.flags & DDPF_CHASECAM))
player->shared.mo->ddFlags = oldFlags;
Expand All @@ -897,9 +898,6 @@ void R_RenderPlayerView(int num)
}

R_InfoRendVerticesPool();

// The colored filter.
GL_DrawFilter();
}

/**
Expand Down Expand Up @@ -969,6 +967,17 @@ void R_RenderViewPorts(void)
continue;
}

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

/**
* Use an orthographic projection in native screenspace. Then
* translate and scale the projection to produce an aspect
* corrected coordinate space at 4:3.
*/
glOrtho(0, vp->width, vp->height, 0, -1, 1);

// Draw in-window game graphics (layer 0).
gx.G_Drawer(0);
restoreDefaultGLState();
Expand All @@ -980,6 +989,9 @@ void R_RenderViewPorts(void)
gx.G_Drawer(1);
restoreDefaultGLState();

glMatrixMode(GL_PROJECTION);
glPopMatrix();

// Increment the internal frame count. This does not
// affect the FPS counter.
frameCount++;
Expand Down
8 changes: 4 additions & 4 deletions doomsday/plugins/common/src/g_controls.c
Expand Up @@ -409,10 +409,10 @@ DEFCC( CCmdDefaultGameBinds )
"bindevent key-h {impulse showhud}",
"bindevent key-backslash-down {impulse showscore}",
"bindevent key-backslash-repeat {impulse showscore}",
"bindevent key-minus-down {viewsize -}",
"bindevent key-minus-repeat {viewsize -}",
"bindevent key-equals-down {viewsize +}",
"bindevent key-equals-repeat {viewsize +}",
"bindevent key-minus-down {sub view-size 1}",
"bindevent key-minus-repeat {sub view-size 1}",
"bindevent key-equals-down {add view-size 1}",
"bindevent key-equals-repeat {add view-size 1}",

// Player message log:
#if !defined(__JHEXEN__) && !defined(__JHERETIC__)
Expand Down
1 change: 0 additions & 1 deletion doomsday/plugins/common/src/g_game.c
Expand Up @@ -675,7 +675,6 @@ void G_CommonPostInit(void)
XG_Register(); // Register XG classnames.
#endif

R_SetViewSize(cfg.screenBlocks);
R_SetBorderGfx(borderLumps);

Con_Message("P_Init: Init Playloop state.\n");
Expand Down
16 changes: 6 additions & 10 deletions doomsday/plugins/common/src/hu_menu.c
Expand Up @@ -3079,7 +3079,7 @@ void M_DrawHUDMenu(void)
#if __JHERETIC__ || __JHEXEN__
idx++;
#endif
MN_DrawSlider(menu, idx++, 11, cfg.screenBlocks - 3);
MN_DrawSlider(menu, idx++, 11, cfg.setBlocks - 3);
#if __JHERETIC__ || __JHEXEN__
idx++;
#endif
Expand Down Expand Up @@ -3321,8 +3321,6 @@ void M_SizeStatusBar(int option, void* context)
cfg.statusbarScale--;

ST_HUDUnHide(CONSOLEPLAYER, HUE_FORCE);

R_SetViewSize(cfg.screenBlocks);
}

void M_StatusBarOpacity(int option, void* context)
Expand Down Expand Up @@ -3722,20 +3720,18 @@ void M_SizeDisplay(int option, void* context)
if(option == RIGHT_DIR)
{
#if __JDOOM64__
if(cfg.screenBlocks < 11)
if(cfg.setBlocks < 11)
#else
if(cfg.screenBlocks < 13)
if(cfg.setBlocks < 13)
#endif
{
cfg.screenBlocks++;
cfg.setBlocks++;
}
}
else if(cfg.screenBlocks > 3)
else if(cfg.setBlocks > 3)
{
cfg.screenBlocks--;
cfg.setBlocks--;
}

R_SetViewSize(cfg.screenBlocks);
}

void M_OpenDCP(int option, void* context)
Expand Down
4 changes: 3 additions & 1 deletion doomsday/plugins/common/src/hu_pspr.c
Expand Up @@ -89,9 +89,11 @@ static float PSpriteSY[NUM_PLAYER_CLASSES][NUM_WEAPON_TYPES] = {
*/
float HU_PSpriteYOffset(player_t* pl)
{
int viewWindowHeight = Get(DD_VIEWWINDOW_HEIGHT);
float viewWindowHeight;
float offy = (cfg.plrViewHeight - DEFAULT_PLAYER_VIEWHEIGHT) * 2;

R_GetViewWindow(NULL, NULL, NULL, &viewWindowHeight);

#if __JHERETIC__
if(viewWindowHeight == SCREENHEIGHT)
offy += PSpriteSY[pl->morphTics? PCLASS_CHICKEN : pl->class][pl->readyWeapon];
Expand Down
4 changes: 2 additions & 2 deletions doomsday/plugins/common/src/m_ctrl.c
Expand Up @@ -305,8 +305,8 @@ static controlconfig_t controlConfig[] =
{ "hud" },
{ "show hud", 0, 0, "impulse showhud" },
{ "show score", 0, 0, "impulse showscore", CCF_REPEAT },
{ "smaller view", 0, 0, "viewsize -", CCF_REPEAT },
{ "larger view", 0, 0, "viewsize +", CCF_REPEAT },
{ "smaller view", 0, 0, "sub view-size 1", CCF_REPEAT },
{ "larger view", 0, 0, "add view-size 1", CCF_REPEAT },

{ "message refresh", 0, 0, "impulse msgrefresh" },

Expand Down

0 comments on commit 10c8623

Please sign in to comment.