Linux problems

I’m having some odd problems with SDL2.0.2 on Ubuntu Linux - Line drawing works okay, but drawing a rectangle doesn’t - nothing is display no matter what colour is used.

In addition, SDL_ttf isn’t working properly either - a surface is being created but again, nothing is being displayed.

My rectangle routine is thus :

Code:

SDL_Rect rect;

rect.x=sx;

rect.y=sy;

rect.w=ex;

rect.h=ey;

// SDL_SetRenderDrawBlendMode(m_mainRenderer,blendModes[DRAW-TEXTURE].mode);

//SDL_SetRenderDrawColor(m_mainRenderer,RGBR(col),RGBG(col),RGBB(col),SDL_ALPHA_OPAQUE);

if (SDL_RenderFillRect(m_mainRenderer,(SDL_Rect *) &rect)!=0)
{
    DEBUG("Error!");

}

No error is being reported with RenderFillRect and the main renderer has been set up.

It all works fine in Windows!

Can you post your complete test code that reproduces the issue?On Fri, Aug 15, 2014 at 5:37 PM, MrTAToad wrote:

I’m having some odd problems with SDL2.0.2 on Ubuntu Linux - Line
drawing works okay, but drawing a rectangle doesn’t - nothing is display no
matter what colour is used.

In addition, SDL_ttf isn’t working properly either - a surface is being
created but again, nothing is being displayed.

My rectangle routine is thus :

Code:

SDL_Rect rect;

rect.x=sx;

rect.y=sy;

rect.w=ex;

rect.h=ey;

//
SDL_SetRenderDrawBlendMode(m_mainRenderer,blendModes[DRAW-TEXTURE].mode);

//SDL_SetRenderDrawColor(m_mainRenderer,RGBR(col),RGBG(col),RGBB(col),SDL_ALPHA_OPAQUE);

if (SDL_RenderFillRect(m_mainRenderer,(SDL_Rect *) &rect)!=0)
{
    DEBUG("Error!");

}

No error is being reported with RenderFillRect and the main renderer has
been set up.

It all works fine in Windows!


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

My test code is :

Code:
#include <Triority.h>

int main(int argc,char *argv[])
{
if (__GLB_Defaults(argc,argv,“linux”,“test”)==false)
{
END();
return false;
}

//SETSCREEN(640,480,false);
//SETFONT(0);
FONTCOLOUR(0);
CLEARSCREEN(0);
while (true)
{
    //ALPHAMODE(-1.0);
    DRAWRECT(0,0,100,100,GLRGB(255,0,0));
    DRAWLINE(0,0,300,300,GLRGB(0,0,255));

    ALPHAMODE(0);
    if (PRINT("Test",100,100)==false)
    {
        DEBUG("Error : "+GETLASTERROR_Str()+"\n");
    }

    SHOWSCREEN();

}
return true;

}

For the sake of sanity, you’ll also have to include definitions for
DRAWRECT, DRAWLINE, ALPHAMODE, and SHOWSCREEN, as well as your SDL init
code (I presume that’s inside __GLB_defaults() ?), since it would be most
helpful for debugging the code that’s directly using SDL.On Fri, Aug 15, 2014 at 6:52 PM, MrTAToad wrote:

My test code is :

Code:

#include

int main(int argc,char *argv[])
{
if (__GLB_Defaults(argc,argv,“linux”,“test”)==false)
{
END();
return false;
}

//SETSCREEN(640,480,false);
//SETFONT(0);
FONTCOLOUR(0);
CLEARSCREEN(0);
while (true)
{
    //ALPHAMODE(-1.0);
    DRAWRECT(0,0,100,100,GLRGB(255,0,0));
    DRAWLINE(0,0,300,300,GLRGB(0,0,255));

    ALPHAMODE(0);
    if (PRINT("Test",100,100)==false)
    {
        DEBUG("Error : "+GETLASTERROR_Str()+"\n");
    }

    SHOWSCREEN();

}
return true;

}


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

My Triority system can be downloaded from : https://onedrive.live.com/redir?resid=C74F6DC48C7A65C9!1049

__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(amount
255.0));
}
}
else
{
BLENDMODE(SDL_BLENDMODE_NONE); ALPHALEVEL(255);
}
}

I also have the same problem with the slightly amended code from the SDL wiki :

Code:
#include “SDL.h”

int main(int argc, char *argv[]) {
SDL_Window *win = NULL;
SDL_Renderer *renderer = NULL;
SDL_Texture *bitmapTex = NULL;
SDL_Surface *bitmapSurface = NULL;
int posX = 100, posY = 100, width = 320, height = 240;
SDL_Rect rect;

win = SDL_CreateWindow("Hello World", posX, posY, width, height, 0);

renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);

bitmapSurface = SDL_LoadBMP("img/hello.bmp");
bitmapTex = SDL_CreateTextureFromSurface(renderer, bitmapSurface);
SDL_FreeSurface(bitmapSurface);

while (1) {
    SDL_Event e;
    if (SDL_PollEvent(&e)) {
        if (e.type == SDL_QUIT) {
            break;
        }
    }

    rect.x=10;
    rect.y=10;
    rect.w=50;
    rect.h=50;

    SDL_SetRenderDrawColor(renderer,255,0,255,255);
    SDL_RenderClear(renderer);
    SDL_RenderCopy(renderer, bitmapTex, NULL, NULL);
    SDL_SetRenderDrawColor(renderer,255,0,0,255);
    SDL_RenderFillRect(renderer,&rect);
    SDL_RenderPresent(renderer);
}

However, changing to a non-filled rectangle and all is okay…

Think I’ve solved the problem!

Despite protestations to the contrary, it appears that VMPlayer drivers aren’t hardware accelerated, hence the cause of the problem. Changing to a software driver solves the problem…

It looks like TextureBlendMode isn’t available for software rendering…