Add SetBlendMode;

add glexts.h;
log version and available extensions;
implement real glow with GL_EXT_texture_env_combine.
This commit is contained in:
Glenn Maynard
2002-11-12 00:51:27 +00:00
parent 3cca0545d0
commit 5673bec6f2
2 changed files with 63 additions and 26 deletions
+61 -26
View File
@@ -18,15 +18,21 @@
#include "RageException.h" #include "RageException.h"
#include "RageTexture.h" #include "RageTexture.h"
#include "RageMath.h" #include "RageMath.h"
#include "SDL.h"
#include "SDL_opengl.h"
#include "RageTypes.h" #include "RageTypes.h"
#include "GameConstantsAndTypes.h" #include "GameConstantsAndTypes.h"
#include <set>
#include "SDL.h"
/* ours is more up-to-date */
#define NO_SDL_GLEXT
#include "SDL_opengl.h"
#include "glext.h"
PFNGLBLENDFUNCSEPARATEPROC glBlendFuncSeparate;
RageDisplay* DISPLAY = NULL; RageDisplay* DISPLAY = NULL;
//////////// ////////////
// Globals // Globals
//////////// ////////////
@@ -51,6 +57,20 @@ int RageDisplay::GetDPF() const { return g_iDPF; }
static int g_iFramesRenderedSinceLastCheck, static int g_iFramesRenderedSinceLastCheck,
g_iVertsRenderedSinceLastCheck, g_iVertsRenderedSinceLastCheck,
g_iDrawsSinceLastCheck; g_iDrawsSinceLastCheck;
set<string> g_glExts;
static bool g_GL_EXT_texture_env_combine;
void GetGLExtensions(set<string> &ext)
{
const char *buf = (const char *)glGetString(GL_EXTENSIONS);
vector<CString> lst;
split(buf, " ", lst);
for(unsigned i = 0; i < lst.size(); ++i)
ext.insert(lst[i]);
LOG->Trace("OpenGL extensions: %s", buf);
}
RageDisplay::RageDisplay( bool windowed, int width, int height, int bpp, RefreshRateMode rate, bool vsync ) RageDisplay::RageDisplay( bool windowed, int width, int height, int bpp, RefreshRateMode rate, bool vsync )
{ {
@@ -59,6 +79,8 @@ RageDisplay::RageDisplay( bool windowed, int width, int height, int bpp, Refresh
SDL_InitSubSystem(SDL_INIT_VIDEO); SDL_InitSubSystem(SDL_INIT_VIDEO);
SetVideoMode( windowed, width, height, bpp, rate, vsync ); SetVideoMode( windowed, width, height, bpp, rate, vsync );
glBlendFuncSeparate = (PFNGLBLENDFUNCSEPARATEPROC) SDL_GL_GetProcAddress ("glBlendFuncSeparate");
} }
RageDisplay::~RageDisplay() RageDisplay::~RageDisplay()
@@ -66,7 +88,6 @@ RageDisplay::~RageDisplay()
SDL_QuitSubSystem(SDL_INIT_VIDEO); SDL_QuitSubSystem(SDL_INIT_VIDEO);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Name: SwitchDisplayMode() // Name: SwitchDisplayMode()
// Desc: // Desc:
@@ -115,6 +136,9 @@ void RageDisplay::SetVideoMode( bool windowed, int width, int height, int bpp, R
g_glVersion = int(roundf(atof((const char *) glGetString(GL_VERSION)) * 10)); g_glVersion = int(roundf(atof((const char *) glGetString(GL_VERSION)) * 10));
LOG->Trace( "OpenGL version %.1f", g_glVersion / 10.); LOG->Trace( "OpenGL version %.1f", g_glVersion / 10.);
GetGLExtensions(g_glExts);
if(g_glExts.find("GL_EXT_texture_env_combine") != g_glExts.end())
g_GL_EXT_texture_env_combine = true;
/* /*
* Set up OpenGL for 2D rendering. * Set up OpenGL for 2D rendering.
@@ -360,38 +384,49 @@ void RageDisplay::SetTextureModeModulate()
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
} }
/* Set the blend mode for both texture and alpha. This is all that's
* available pre-OpenGL 1.4. */
void RageDisplay::SetBlendMode(int src, int dst)
{
int a, b;
glGetIntegerv( GL_BLEND_SRC, &a );
glGetIntegerv( GL_BLEND_DST, &b );
if( a!=src || b!=dst )
FlushQueue();
glBlendFunc( src, dst );
}
void RageDisplay::SetTextureModeGlow() void RageDisplay::SetTextureModeGlow()
{ {
int a, b; if(!g_GL_EXT_texture_env_combine) {
glGetIntegerv( GL_BLEND_SRC, &a ); SetBlendMode( GL_SRC_ALPHA, GL_ONE );
glGetIntegerv( GL_BLEND_DST, &b ); return;
}
if( a!=GL_SRC_ALPHA || b!=GL_ONE ) FlushQueue();
FlushQueue();
glBlendFunc( GL_SRC_ALPHA, GL_ONE ); /* Source color is the diffuse color only: */
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_PRIMARY_COLOR_EXT);
/* Source alpha is texture alpha * diffuse alpha: */
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT, GL_SRC_ALPHA);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_PRIMARY_COLOR_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_EXT, GL_SRC_ALPHA);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT, GL_TEXTURE);
} }
void RageDisplay::SetBlendModeNormal() void RageDisplay::SetBlendModeNormal()
{ {
int a, b; SetBlendMode( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glGetIntegerv( GL_BLEND_SRC, &a );
glGetIntegerv( GL_BLEND_DST, &b );
if( a!=GL_SRC_ALPHA || b!=GL_ONE_MINUS_SRC_ALPHA )
FlushQueue();
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
} }
void RageDisplay::SetBlendModeAdd() void RageDisplay::SetBlendModeAdd()
{ {
int a, b; SetBlendMode( GL_ONE, GL_ONE );
glGetIntegerv( GL_BLEND_SRC, &a );
glGetIntegerv( GL_BLEND_DST, &b );
if( a!=GL_ONE || b!=GL_ONE )
FlushQueue();
glBlendFunc( GL_ONE, GL_ONE );
} }
void RageDisplay::EnableZBuffer() void RageDisplay::EnableZBuffer()
{ {
+2
View File
@@ -53,6 +53,7 @@ public:
void RotateZ( float r ); void RotateZ( float r );
void SetTexture( RageTexture* pTexture ); void SetTexture( RageTexture* pTexture );
void SetTextureModeModulate(); void SetTextureModeModulate();
void SetTextureModeGlow(); void SetTextureModeGlow();
void SetBlendModeNormal(); void SetBlendModeNormal();
@@ -78,6 +79,7 @@ public:
protected: protected:
void AddVerts( const RageVertex v[], int iNumVerts ); void AddVerts( const RageVertex v[], int iNumVerts );
void SetBlendMode(int src, int dst);
}; };