WIP: show 3d models in player setup

this is incredibly ugly and hacked together
theres some weird culling issues and shit doesent really "scale" with different resolutions which needs to be fixed
but it kinda works
This commit is contained in:
Alug committed 2026-01-12 18:29:55 +01:00
1 parent 264c9e38ad
commit b145d7fd0e
5 files changed
+212 -8

No files matched your search

+3
View File
@@ -80,6 +80,9 @@ UINT32 GL_CreateLightTable(RGBA_t *hw_lighttable);
void GL_ClearLightTables(void);
void GL_SetScreenPalette(RGBA_t *palette);
void GL_Draw2DModel(model_t *model, INT32 frameIndex, INT32 duration, INT32 tics, INT32 nextFrameIndex,
FTransform *pos, float hscale, float vscale, UINT8 flipped, UINT8 hflipped, FSurfaceInfo *Surface);
#ifdef __cplusplus
} // extern "C"
#endif
+111
View File
@@ -1475,4 +1475,115 @@ void HWR_DrawMD2(gl_vissprite_t *spr)
}
}
// mostly copy paste of HWR_DrawMD2
// very ugly but our model code kinda sucks
void HWR_Draw2DModel(md2_t *md2, INT32 x, INT32 y, INT32 skinnum, skincolors_t color, const UINT8 *colormap, fixed_t scale, INT32 frame, angle_t angle)
{
patch_t *gpatch, *blendgpatch;
GLPatch_t *hwrPatch = NULL, *hwrBlendPatch = NULL;
FTransform p;
FSurfaceInfo Surf;
if (!md2->model)
{
char filename[64];
CONS_Debug(DBG_RENDER, "Loading model... (%s)\n", md2->filename);
sprintf(filename, "mdls/%s", md2->filename);
md2->model = md2_readModel(filename);
if (md2->model)
{
md2_printModelInfo(md2->model);
GL_CreateModelVBOs(md2->model);
}
else
{
md2->error = true;
return;
}
}
if (md2->model->meshes[0].numFrames > 0)
frame = frame % md2->model->meshes[0].numFrames;
else
frame = 0;
gpatch = static_cast<patch_t *>(md2->glpatch);
if (gpatch)
hwrPatch = ((GLPatch_t *)gpatch->hardware);
if (!gpatch || !hwrPatch ||
((!hwrPatch->mipmap->format || !hwrPatch->mipmap->downloaded) && !md2->notexturefile))
md2_loadTexture(md2);
gpatch = static_cast<patch_t *>(md2->glpatch);
if (gpatch)
hwrPatch = ((GLPatch_t *)gpatch->hardware);
blendgpatch = static_cast<patch_t *>(md2->blendglpatch);
if (blendgpatch)
hwrBlendPatch = ((GLPatch_t *)blendgpatch->hardware);
if ((gpatch && hwrPatch && hwrPatch->mipmap->format) &&
(!blendgpatch || !hwrBlendPatch ||
((!hwrBlendPatch->mipmap->format || !hwrBlendPatch->mipmap->downloaded) && !md2->noblendfile)))
md2_loadBlendTexture(md2);
blendgpatch = static_cast<patch_t *>(md2->blendglpatch);
if (blendgpatch)
hwrBlendPatch = ((GLPatch_t *)blendgpatch->hardware);
memset(&Surf, 0x00, sizeof(FSurfaceInfo));
Surf.PolyColor.rgba = 0xFFFFFFFF;
Surf.PolyFlags = PF_Occlude | PF_Modulated;
Surf.LightInfo.light_level = 255;
Surf.LightInfo.fade_start = 0;
Surf.LightInfo.fade_end = 31;
if (color != SKINCOLOR_NONE &&
blendgpatch && hwrBlendPatch->mipmap->format &&
gpatch->width == blendgpatch->width && gpatch->height == blendgpatch->height)
{
INT32 tcskinnum = TC_DEFAULT;
if (color)
tcskinnum = skinnum;
HWR_GetBlendedTexture(gpatch, blendgpatch, tcskinnum, colormap, color);
}
else if (hwrPatch && hwrPatch->mipmap->format)
{
GL_SetTexture(hwrPatch->mipmap);
}
memset(&p, 0x00, sizeof(FTransform));
p.x = x;
p.y = -400.0f; // idk man, but this makes the model not cull, kinda?
p.z = y; // for whatever reason y and z are switched here
p.angley = FixedToFloat(AngleFixed(angle));
p.anglex = 0.0f;
p.anglez = 0.0f;
p.roll = false;
p.fliptype = TRANSFORM_NONE;
GL_Draw2DModel(
md2->model,
frame,
0.0f,
0.0f,
-1,
&p,
FixedToFloat(scale),
FixedToFloat(scale),
true,
false,
&Surf
);
}
#endif //HWRENDER
+3
View File
@@ -45,6 +45,9 @@ void HWR_InitMD2(void);
void HWR_DrawMD2(gl_vissprite_t *spr);
void HWR_AddPlayerMD2(INT32 skin, boolean local);
void HWR_AddSpriteMD2(size_t spritenum);
void HWR_Draw2DModel(md2_t *md2, INT32 x, INT32 y, INT32 skinnum,
skincolors_t color, const UINT8 *colormap,
fixed_t scale, INT32 frame, angle_t angle);
#ifdef __cplusplus
} // extern "C"
+52
View File
@@ -404,6 +404,14 @@ static PFNglEnableClientState pglEnableClientState;
typedef void (APIENTRY * PFNglDisableClientState) (GLenum cap);
static PFNglDisableClientState pglDisableClientState;
typedef void (APIENTRY * PFNglOrtho) (GLdouble left,
GLdouble right,
GLdouble bottom,
GLdouble top,
GLdouble nearVal,
GLdouble farVal);
static PFNglOrtho pglOrtho;
/* Lighting */
typedef void (APIENTRY * PFNglShadeModel) (GLenum mode);
static PFNglShadeModel pglShadeModel;
@@ -858,6 +866,8 @@ void SetupGLFunc4(void)
GetGLfunc(glUniform3fv);
GetGLfunc(glGetUniformLocation);
GetGLfunc(glOrtho);
#ifdef GLDEBUGMESSAGE
GetGLfunc(glDebugMessageCallback);
#endif
@@ -3090,6 +3100,48 @@ void GL_DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics
pglDisable(GL_NORMALIZE);
}
void GL_Draw2DModel(model_t *model, INT32 frameIndex, INT32 duration, INT32 tics, INT32 nextFrameIndex,
FTransform *pos, float hscale, float vscale, UINT8 flipped, UINT8 hflipped, FSurfaceInfo *Surface)
{
// save our matrix´s
pglMatrixMode(GL_PROJECTION);
pglPushMatrix();
pglMatrixMode(GL_MODELVIEW);
pglPushMatrix();
pglMatrixMode(GL_PROJECTION);
pglLoadIdentity();
// switch to ortho mode to make our lives easier
// thisll make sure our coords will be remapped to pixel coords
// try to scale it to the base width and height
// shit still be weird, and needs accounting for diff resolutions
pglOrtho(0.0f, (float)BASEVIDWIDTH, (float)BASEVIDHEIGHT, 0.0f, ZCLIP_PLANE, FAR_ZCLIP_DEFAULT);
pglMatrixMode(GL_MODELVIEW);
pglLoadIdentity();
//pglDepthRange(0.0f, 1.0f);
pglClearDepth(1.0f); //Hurdler: all that are permanen states
pglDepthRange(ZCLIP_PLANE, FAR_ZCLIP_DEFAULT); // idk man im confused here tbh
pglDepthFunc(GL_LEQUAL);
pglClear(GL_DEPTH_BUFFER_BIT);
//GL_ClearBuffer(false, true, false, NULL);
// FIXME: theres some weird culling issues i cant wrap my head around
// so until then gotta disable depth testing until i can figure this out
//pglDisable(GL_DEPTH_TEST);
GL_DrawModelEx(model, frameIndex, duration, tics, nextFrameIndex,
pos, hscale, vscale, flipped, hflipped, Surface);
//pglEnable(GL_DEPTH_TEST);
// restore the matrix´s
pglMatrixMode(GL_PROJECTION);
pglPopMatrix();
pglMatrixMode(GL_MODELVIEW);
pglPopMatrix();
}
// -----------------+
// SetTransform :
// -----------------+
+43 -8
View File
@@ -12,6 +12,8 @@
/// \file m_menu.c
/// \brief XMOD's extremely revamped menu system.
#include "screen.h"
#include "tables.h"
#ifdef __GNUC__
#include <unistd.h>
#endif
@@ -8523,7 +8525,7 @@ static void M_DrawSetupMultiPlayerMenu(void)
const INT32 skinnum = R_SkinAvailable(skins[skintodisplay].name);
if (skinnum != -1)
if (skinnum > 0 || skinnum < MAXSKINS)
sprdef = &skins[skinnum].spritedef;
else
sprdef = &skins[0].spritedef;
@@ -8549,23 +8551,56 @@ static void M_DrawSetupMultiPlayerMenu(void)
// draw box around guy
V_DrawFill(mx + 36 - (charw/2), my+65, charw, 84, 239);
#undef charw
// draw player sprite
if (setupm_fakecolor) // inverse should never happen
{
UINT8 *colormap = R_GetTranslationColormap(skintodisplay, setupm_fakecolor, GTC_MENUCACHE);
if (skins[skintodisplay].flags & SF_HIRES)
#ifdef HWRENDER
md2_t *md2 = NULL;
if (skinnum > 0 || skinnum < MAXSKINS)
md2 = &md2_playermodels[skinnum];
else
md2 = &md2_playermodels[0];
// if we have 3d models enabled and a model exists
// try to show it instead of the sprite
if (rendermode == render_opengl && cv_glmdls.value
&& !md2->error && !md2->notfound)
{
V_DrawFixedPatch((mx+36)<<FRACBITS,
(my+131)<<FRACBITS,
skins[skintodisplay].highresscale,
flags, patch, colormap);
mx += 36;
my += 131;
static angle_t angle = ANGLE_180;
// idk but those magic numbers work, gotta figure out smth proper
//x += vid.width/3;
//y += vid.height/2;
mx += BASEVIDWIDTH/8;
my -= BASEVIDHEIGHT/10;
// just for testing
angle += FRACUNIT * 3;
HWR_Draw2DModel(md2, mx, my, skinnum, (skincolors_t)setupm_fakecolor, colormap, 4*FRACUNIT/3, 0, angle);
}
else
V_DrawMappedPatch(mx+36, my+131, flags, patch, colormap);
#endif
{
if (skins[skintodisplay].flags & SF_HIRES)
{
V_DrawFixedPatch((mx+36)<<FRACBITS,
(my+131)<<FRACBITS,
skins[skintodisplay].highresscale,
flags, patch, colormap);
}
else
V_DrawMappedPatch(mx+36, my+131, flags, patch, colormap);
}
}
#undef charw
}
// Handle 1P/2P MP Setup