From 21245926e54e248ae9378f34b50eddd48c759b38 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 25 Jan 2003 03:57:14 +0000 Subject: [PATCH] add fallback line renderer (not yet used) --- stepmania/src/RageDisplay.cpp | 76 +++++++++++++++++++++++++++++++++-- stepmania/src/RageDisplay.h | 4 ++ 2 files changed, 77 insertions(+), 3 deletions(-) diff --git a/stepmania/src/RageDisplay.cpp b/stepmania/src/RageDisplay.cpp index 4de9e4da0c..e9c5c8d9e5 100644 --- a/stepmania/src/RageDisplay.cpp +++ b/stepmania/src/RageDisplay.cpp @@ -24,6 +24,8 @@ #include "GameConstantsAndTypes.h" #include "StepMania.h" +#include + RageDisplay* DISPLAY = NULL; //////////// @@ -456,7 +458,67 @@ void RageDisplay::DrawStrip( const RageVertex v[], int iNumVerts ) g_iVertsRenderedSinceLastCheck += iNumVerts; } -void RageDisplay::DrawLoop( const RageVertex v[], int iNumVerts, float LineWidth ) +/* Draw a line as a quad. GL_LINES with antialiasing off can draw odd + * ends at odd angles--they're forced to axis-alignment regardless of the + * angle of the line. */ +void RageDisplay::DrawPolyLine(const RageVertex &p1, const RageVertex &p2, float LineWidth ) +{ + /* soh cah toa strikes strikes again! */ + float opp = p2.p.x - p1.p.x; + float adj = p2.p.y - p1.p.y; + float hyp = powf(opp*opp + adj*adj, 0.5f); + + float lsin = opp/hyp; + float lcos = adj/hyp; + + RageVertex p[4]; + p[0] = p[1] = p1; + p[2] = p[3] = p2; + + float ydist = lsin * LineWidth/2; + float xdist = lcos * LineWidth/2; + + p[0].p.x += xdist; + p[0].p.y -= ydist; + p[1].p.x -= xdist; + p[1].p.y += ydist; + p[2].p.x -= xdist; + p[2].p.y += ydist; + p[3].p.x += xdist; + p[3].p.y -= ydist; + + DrawQuad(p); +} + +/* Draw a line loop with rounded corners using polys. This is used on + * cards that have strange allergic reactions to antialiased points and + * lines. */ +void RageDisplay::DrawLoop_Polys( const RageVertex v[], int iNumVerts, float LineWidth ) +{ + ASSERT( iNumVerts >= 3 ); + + for(int i = 0; i < iNumVerts; ++i) + DrawPolyLine(v[i], v[(i+1)%iNumVerts], LineWidth); + + /* Join the lines with circles so we get rounded corners. */ + GLUquadricObj *q = gluNewQuadric(); + for(int i = 0; i < iNumVerts; ++i) + { + glPushMatrix(); + glColor4fv(v[i].c); + glTexCoord3fv(v[i].t); + glTranslatef(v[i].p.x, v[i].p.y, v[i].p.z); + + gluDisk(q, 0, LineWidth/2, 32, 32); + glPopMatrix(); + } + gluDeleteQuadric(q); +} + +/* Draw a nice AA'd line loop. One problem with this is that point and line + * sizes don't always precisely match, which doesn't look quite right. + * It's worth it for the AA, though. */ +void RageDisplay::DrawLoop_LinesAndPoints( const RageVertex v[], int iNumVerts, float LineWidth ) { ASSERT( iNumVerts >= 3 ); @@ -478,7 +540,6 @@ void RageDisplay::DrawLoop( const RageVertex v[], int iNumVerts, float LineWidth * if lines are .5 and points are .25, we might want to snap the width to the * nearest .5, so the hardware doesn't snap them to different sizes. Does it * matter? */ - glLineWidth(LineWidth); /* Draw the line loop: */ @@ -496,7 +557,9 @@ void RageDisplay::DrawLoop( const RageVertex v[], int iNumVerts, float LineWidth * any points at all, since there's nothing to connect. That'll happen * if both scale factors in the matrix are ~0. (Actually, I think * it's true if two of the three scale factors are ~0, but we don't - * use this for anything 3d at the moment anyway ...) */ + * use this for anything 3d at the moment anyway ...) This is needed + * because points aren't scaled like regular polys--a zero-size point + * will still be drawn. */ RageMatrix mat; glGetFloatv( GL_MODELVIEW_MATRIX, (float*)mat ); @@ -511,6 +574,13 @@ void RageDisplay::DrawLoop( const RageVertex v[], int iNumVerts, float LineWidth glDisable(GL_POINT_SMOOTH); } +void RageDisplay::DrawLoop( const RageVertex v[], int iNumVerts, float LineWidth ) +{ + /* XXX: need to autodetect voodoo 3500 (and any others that need this) */ +// DrawLoop_LinesAndPoints(v, iNumVerts, LineWidth); + DrawLoop_Polys(v, iNumVerts, LineWidth); +} + void RageDisplay::PushMatrix() { glPushMatrix(); diff --git a/stepmania/src/RageDisplay.h b/stepmania/src/RageDisplay.h index 9531fe874e..d8a03263bc 100644 --- a/stepmania/src/RageDisplay.h +++ b/stepmania/src/RageDisplay.h @@ -97,6 +97,10 @@ protected: /* Don't use this to check extensions; use GetSpecs. */ bool HasExtension(CString ext) const; void RageDisplay::DumpOpenGLDebugInfo(); + + void DrawPolyLine(const RageVertex &p1, const RageVertex &p2, float LineWidth ); + void DrawLoop_LinesAndPoints( const RageVertex v[], int iNumVerts, float LineWidth ); + void DrawLoop_Polys( const RageVertex v[], int iNumVerts, float LineWidth ); };