# Linux problems

**URL:** <https://discourse.libsdl.org/t/linux-problems/20913>\
**Category:** SDL Development\
**Created:** [August 15, 2014, 9:37pm UTC](https://discourse.libsdl.org/t/linux-problems/20913 "2014-08-15T21:37:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![MrTAToad](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/73ab20/32.png) [@MrTAToad](https://discourse.libsdl.org/u/MrTAToad)\
**Post date:** [August 15, 2014, 9:37pm UTC](https://discourse.libsdl.org/t/linux-problems/20913/1 "2014-08-15T21:37:46Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Alex\_Barry](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/alex_barry/32/515_2.png) [@Alex\_Barry](https://discourse.libsdl.org/u/Alex_Barry)\
**Post date:** [August 15, 2014, 9:51pm UTC](https://discourse.libsdl.org/t/linux-problems/20913/2 "2014-08-15T21:51:30Z")

</div>

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)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![MrTAToad](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/73ab20/32.png) [@MrTAToad](https://discourse.libsdl.org/u/MrTAToad)\
**Post date:** [August 15, 2014, 10:52pm UTC](https://discourse.libsdl.org/t/linux-problems/20913/3 "2014-08-15T22:52:19Z")

</div>

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;

```

}

---

<div class="post-metadata">

**Author:** ![Alex\_Barry](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/alex_barry/32/515_2.png) [@Alex\_Barry](https://discourse.libsdl.org/u/Alex_Barry)\
**Post date:** [August 15, 2014, 10:55pm UTC](https://discourse.libsdl.org/t/linux-problems/20913/4 "2014-08-15T22:55:31Z")

</div>

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)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![MrTAToad](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/73ab20/32.png) [@MrTAToad](https://discourse.libsdl.org/u/MrTAToad)\
**Post date:** [August 15, 2014, 10:55pm UTC](https://discourse.libsdl.org/t/linux-problems/20913/5 "2014-08-15T22:55:38Z")

</div>

My Triority system can be downloaded from : [https://onedrive.live.com/redir?resid=C74F6DC48C7A65C9!1049](https://onedrive.live.com/redir?resid=C74F6DC48C7A65C9%211049)

---

<div class="post-metadata">

**Author:** ![MrTAToad](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/73ab20/32.png) [@MrTAToad](https://discourse.libsdl.org/u/MrTAToad)\
**Post date:** [August 16, 2014, 10:23am UTC](https://discourse.libsdl.org/t/linux-problems/20913/6 "2014-08-16T10:23:09Z")

</div>

\_\_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);  
}  
}

---

<div class="post-metadata">

**Author:** ![MrTAToad](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/73ab20/32.png) [@MrTAToad](https://discourse.libsdl.org/u/MrTAToad)\
**Post date:** [August 16, 2014, 1:10pm UTC](https://discourse.libsdl.org/t/linux-problems/20913/7 "2014-08-16T13:10:13Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![MrTAToad](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/73ab20/32.png) [@MrTAToad](https://discourse.libsdl.org/u/MrTAToad)\
**Post date:** [August 16, 2014, 1:57pm UTC](https://discourse.libsdl.org/t/linux-problems/20913/8 "2014-08-16T13:57:27Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![MrTAToad](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/73ab20/32.png) [@MrTAToad](https://discourse.libsdl.org/u/MrTAToad)\
**Post date:** [August 16, 2014, 4:51pm UTC](https://discourse.libsdl.org/t/linux-problems/20913/9 "2014-08-16T16:51:31Z")

</div>

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