__glb_init :
Code:
DGNat __GLB_Defaults(int argc, char * argv[],const char *organisation,const char *programName)
{
int imgFlags = IMG_INIT_JPG | IMG_INIT_PNG | IMG_INIT_TIF;
DGStr progName;
SDL_ClearError();
try
{
if (m_window==NULL)
{
DGNat defaultFontIndex = 0;
if (SDL_Init(SDL_INIT_EVERYTHING)!=0) throw(CMP_SDL_ERROR);
if ((IMG_Init(imgFlags) & imgFlags)!=imgFlags) throw(CMP_SDL_IMG_ERROR);
if (TTF_Init()!=0) throw(CMP_SDL_TTF_ERROR);
if (SDLNet_Init()!=0) throw(CMP_SDL_NET_ERROR);
if (Mix_OpenAudio(22050,AUDIO_S16SYS,2,4096)!=0) throw(CMP_SDL_MIXER_ERROR);
DEBUG("Credits : \n");
DEBUG("Default font created by Paul D. Hunt\n");
DEBUG("Converted to C array by Nicholas Kingslery using GLBasic\n");
DEBUG("Sprite collision detection based on Separating Axis Theorem - original code at http://ragestorm.net/samples/CDRR.C\n");
SDL_zero(viewportRect);
blendModes=new (std::nothrow) struct __blend[MAX_BLEND];
proFontSprites=new (std::nothrow) DGNat[MAX_PROSPRITES];
borderColour=new (std::nothrow) DGNat[MAX_BORDERCOLOURS];
if (blendModes==NULL || proFontSprites==NULL || borderColour==NULL) throw(CMP_OUT_OF_MEMORY);
m_background=new (std::nothrow) struct __sprite;
if (m_background==NULL) throw(CMP_OUT_OF_MEMORY);
m_background->texture=NULL;
setlocale(LC_ALL, "");
isMinimised=false; // Needs to be current window setting
inKeyChar = "";
editChar = "";
DIM(sprites,0);
DIM(fonts,0);
DIM(screens,0);
DIM(files,0);
DIM(sounds,0);
DIM(ini,0);
DIM(modules,0);
DIM(proFonts,0);
DIM(particles,0);
DIM(freeParticles,600);
DIM(liveParticles,0);
// Clear the pro font sprite list
for (int loop = 0; loop<MAX_PROSPRITES; loop++) proFontSprites[loop] = INVALID_HANDLE;
ALLOWESCAPE(ALLOW_ESCAPE | ALLOW_CLOSE | ALLOW_ALTRETURN);
SETTITLE(progName.c_str());
SETSCREEN(640,480,false);
SETBORDERCOLOUR(0,GLRGB(255,255,255));
SETBORDERSIZE(0);
SETBORDERTYPE(SINGLE);
LIMITFPS(75.0,false);
SEEDRND((DGNat) GETTIMERALL());
BLENDMODE(SDL_BLENDMODE_BLEND);
ALPHALEVEL(255);
COLOURLEVEL(GLRGB(255, 255, 255));
SETTRANSPARENCY(0);
CLEARSCREEN(GLRGB(0,0,0));
AUTOPAUSE(true);
FONTCOLOUR(GLRGB(255, 255, 255));
SPRITEHANDLE(TOPLEFT,TOPLEFT);
//LOADBMP(DGStr(""));
if (LOADFONT(defaultFont, defaultFont_FILESIZE, defaultFontIndex, 16) == false)
{
DEBUG("* Warning! Unable to create font from default data. No text will currently be displayed.\n");
}
SETFONT(defaultFontIndex);
SETPROFONT(0);
SETPROFONTCHARSPACING(0);
SETPROFONTLINESPACING(0);
//glEnable( GL_TEXTURE_2D ); // Need this to display a texture
numberOfDesktops=SDL_GetNumVideoDisplays();
__numJoysticks=SDL_NumJoysticks();
DIM(joysticks,__numJoysticks);
for (int loop=0; loop<__numJoysticks; loop++)
{
joysticks(loop)=SDL_JoystickOpen(loop);
}
progName=(programName==NULL ? "Test" : programName);
basePath=SDL_GetBasePath();
prefPath=SDL_GetPrefPath((organisation==NULL ? "GLBasic" : organisation),
progName.c_str());
if (prefPath)
{
CREATEDIR(prefPath);
}
// Process the command line arguments
commandLine="";
for (int loop=0; loop<argc; loop++)
{
if (loop==0)
{
commandLine+=DGStr("\"")+argv[loop]+DGStr("\"");
}
else
{
commandLine+=argv[loop];
}
if (loop<argc-1) commandLine+=" ";
}
// Setup frame time
lastTicks=0;
frameTime=0;
}
return true;
}
catch (const DGNat& error)
{
if (blendModes)
{
delete[] blendModes;
blendModes = NULL;
}
if (proFontSprites)
{
delete[] proFontSprites;
proFontSprites = NULL;
}
if (borderColour)
{
delete[] borderColour;
borderColour = NULL;
}
if (m_background)
{
delete m_background;
m_background = NULL;
}
__Error(error);
return false;
}
}
Drawline :
Code:
void GLBASIC::DRAWLINE(DGNat sx, DGNat sy, DGNat ex, DGNat ey, DGNat col)
{
SDL_SetRenderDrawBlendMode(m_mainRenderer,blendModes[DRAW-TEXTURE].mode);
SDL_SetRenderDrawColor(m_mainRenderer,RGBR(col),RGBG(col),RGBB(col),SDL_ALPHA_OPAQUE);
SDL_RenderDrawLine(m_mainRenderer,sx,sy,ex,ey);
}
Showscreen :
Code:
void GLBASIC::SHOWSCREEN()
{
SDL_RenderPresent(m_mainRenderer);
X_MAKE2D();
ALPHAMODE(0); // Change later!
VIEWPORT(0, 0, -1, -1);
ProcessEvents(false);
}
Alphamode :
Code:
void GLBASIC::ALPHAMODE(DGInt amount)
{
amount=CONSTRAIN(amount,-1.0,3.0);
if (amount<0.0)
{
BLENDMODE(SDL_BLENDMODE_BLEND); ALPHALEVEL((DGNat) ABS(amount*255.0));
}
else if (amount > 0.0)
{
if (amount >= 2.0)
{
BLENDMODE(SDL_BLENDMODE_MOD); ALPHALEVEL((DGNat)ABS((amount - 2.0)255.0));
}
else
{
BLENDMODE(SDL_BLENDMODE_ADD); ALPHALEVEL((DGNat)ABS(amount255.0));
}
}
else
{
BLENDMODE(SDL_BLENDMODE_NONE); ALPHALEVEL(255);
}
}