SDL_RenderPresent example doesn't work with X11 renderer?

Hi, I’m new to SDL and I’m trying to learn SDL 1.3. I tried compiling and running the example for SDL_RenderPresent() given on the wiki at http://wiki.libsdl.org/moin.cgi/SDL_RenderPresent and it failed for me. A window pops up, but it is just black. I played around with it and discovered that it works correctly (i.e. I get a red window) if I force the use of either the opengl or software renderers in the call to SDL_CreateRenderer.

The problem only occurs when the x11 renderer is used, and in that case none of the SDL calls return any error even though something is obviously not working.

Now I doubt if I’m ever going to actually need to use anything other than opengl, but I want to make sure I understand what is going on anyway. Is the x11 renderer not working at the moment, or is there something else I need to do to use it?

Eris

What is your hardware and operating system?On Sat, Nov 20, 2010 at 5:53 PM, Eris wrote:

Hi, I’m new to SDL and I’m trying to learn SDL 1.3. I tried compiling and
running the example for SDL_RenderPresent() given on the wiki at
http://wiki.libsdl.org/moin.cgi/SDL_RenderPresent and it failed for me. A
window pops up, but it is just black. I played around with it and discovered
that it works correctly (i.e. I get a red window) if I force the use of
either the opengl or software renderers in the call to SDL_CreateRenderer.

The problem only occurs when the x11 renderer is used, and in that case
none of the SDL calls return any error even though something is obviously
not working.

Now I doubt if I’m ever going to actually need to use anything other than
opengl, but I want to make sure I understand what is going on anyway. Is the
x11 renderer not working at the moment, or is there something else I need to
do to use it?

Eris


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

MrOzBarry wrote:

What is your hardware and operating system?

OS: Slackware Linux 13.1
Kernel: 2.6.33.4-smp (stock Slackware kernel)

Video card: ATI Radeon HD 4670 with 1Gb ram
Video Driver: ATI Catalyst v10.8

And if it matters:
Motherboard: Gigabyte GA-MA790X-UD4P with BIOS version F10a
CPU: AMD Phenom™ 9750 Quad-Core Processor stepping 03
RAM: 4Gb

Also, I was trying to track this down last night and started with the testdraw2 program in the test directory. It works, so I kept stripping out features from it until it broke. What I found is that if I run an event loop, everything seems to be fine, but if I just do a one shot render and then pause, the render doesn’t always work.

In fact, I found that if I simply add 2 more calls to SDL_RenderPresent() before calling SDL_SetRenderDrawColor and SDL_RenderClear, then the program works about 50% of the time. Adding 4 extra SDL_RenderPresent calls makes the program seem to work all the time.

I recompiled SDL without optimization and tried debugging it. Everything seemed OK to me, but it was 4am and I really don’t know anything about X programming, so I could easily have missed something.

I’m going to try updating my video driver today, since I see there’s newer version available now. Maybe it’s just something going on in X. The intermittent nature of the problem makes me think it’s either some sort of timing issue, or perhaps uninitialized data somewhere, though.

Here’s the test program I’m using. I started with the example from http://wiki.libsdl.org/moin.cgi/SDL_RenderPresent

Code:

#include “SDL.h”

#define USEREPEAT

/* Adding a few more SDL_RenderPresent calls makes the window render correctly,
but only most of the times. Sometimes it still fails.
/
#ifdef USEREPEAT
int main(int argc, char
* argv)
{
if (SDL_Init(SDL_INIT_VIDEO) < 0) return 1;

SDL_Window* window =
SDL_CreateWindow(“SDL_RenderClear”,
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
512, 512,
SDL_WINDOW_SHOWN);
SDL_CreateRenderer(window, -1, 0);

/* Add a couple of SDL_RenderPresent calls and it works about half the time.
Four more calls and it seems reliable.
*/
SDL_RenderPresent();
SDL_RenderPresent();

SDL_SetRenderDrawColor(255, 0, 0, 0);
SDL_RenderClear();
SDL_RenderPresent();

SDL_Delay(2000);
SDL_Quit();
return 0;
}
#endif

/* Run in a loop and everything seems to work, although I suspect what
is happening is that the loop simply causes enough updates to be
performed that the updates which fail are no longer on screen long
enough to see.
Need to examine this more.
/
#ifdef USELOOP
int main(int argc, char
* argv)
{
if (SDL_Init(SDL_INIT_VIDEO) < 0) return 1;

SDL_Window* window =
SDL_CreateWindow(“SDL_RenderClear”,
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
512, 512,
SDL_WINDOW_SHOWN);
SDL_CreateRenderer(window, -1, 0);

int done = 0;
while (!done) {
SDL_Event event;

  while (SDL_PollEvent(&event)) {
 switch (event.type) {
    case SDL_WINDOWEVENT:
       switch (event.window.event) {
	  case SDL_WINDOWEVENT_CLOSE:
	     done = 1;
	     break;
	  }
       break;
    }
 }

  SDL_SetRenderDrawColor(255, 0, 0, 0);
  SDL_RenderClear();
  SDL_RenderPresent();
  } 

// Always be sure to clean up
SDL_Quit();
return 0;
}
#endif

Try doing this:
SDL_CreateRenderer( window, -1, SDL_RENDERER_SINGLEBUFFER );
SDL_SelectRenderer( window );

Either this is an issue with the renderer not being selected, or a problem
with double/triple/x-buffering. If the above code works, awesome, and if
not, let me know and we can do some more troubleshooting.

Take care,
-AlexOn Tue, Nov 23, 2010 at 4:37 PM, Eris wrote:

MrOzBarry wrote:

What is your hardware and operating system?

OS: Slackware Linux 13.1
Kernel: 2.6.33.4-smp (stock Slackware kernel)

Video card: ATI Radeon HD 4670 with 1Gb ram
Video Driver: ATI Catalyst v10.8

And if it matters:
Motherboard: Gigabyte GA-MA790X-UD4P with BIOS version F10a
CPU: AMD Phenom™ 9750 Quad-Core Processor stepping 03
RAM: 4Gb

Also, I was trying to track this down last night and started with the
testdraw2 program in the test directory. It works, so I kept stripping out
features from it until it broke. What I found is that if I run an event
loop, everything seems to be fine, but if I just do a one shot render and
then pause, the render doesn’t always work.

In fact, I found that if I simply add 2 more calls to SDL_RenderPresent()
before calling SDL_SetRenderDrawColor and SDL_RenderClear, then the
program works about 50% of the time. Adding 4 extra SDL_RenderPresent calls
makes the program seem to work all the time.

I recompiled SDL without optimization and tried debugging it. Everything
seemed OK to me, but it was 4am and I really don’t know anything about X
programming, so I could easily have missed something.

I’m going to try updating my video driver today, since I see there’s newer
version available now. Maybe it’s just something going on in X. The
intermittent nature of the problem makes me think it’s either some sort of
timing issue, or perhaps uninitialized data somewhere, though.

Here’s the test program I’m using. I started with the example from
http://wiki.libsdl.org/moin.cgi/SDL_RenderPresent

Code:

#include “SDL.h”

#define USEREPEAT

/* Adding a few more SDL_RenderPresent calls makes the window render
correctly,
but only most of the times. Sometimes it still fails.
/
#ifdef USEREPEAT
int main(int argc, char
* argv)
{
if (SDL_Init(SDL_INIT_VIDEO) < 0) return 1;

SDL_Window* window =
SDL_CreateWindow(“SDL_RenderClear”,
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
512, 512,
SDL_WINDOW_SHOWN);
SDL_CreateRenderer(window, -1, 0);

/* Add a couple of SDL_RenderPresent calls and it works about half the
time.
Four more calls and it seems reliable.
*/
SDL_RenderPresent();
SDL_RenderPresent();

SDL_SetRenderDrawColor(255, 0, 0, 0);
SDL_RenderClear();
SDL_RenderPresent();

SDL_Delay(2000);
SDL_Quit();
return 0;
}
#endif

/* Run in a loop and everything seems to work, although I suspect what
is happening is that the loop simply causes enough updates to be
performed that the updates which fail are no longer on screen long
enough to see.
Need to examine this more.
/
#ifdef USELOOP
int main(int argc, char
* argv)
{
if (SDL_Init(SDL_INIT_VIDEO) < 0) return 1;

SDL_Window* window =
SDL_CreateWindow(“SDL_RenderClear”,
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
512, 512,
SDL_WINDOW_SHOWN);
SDL_CreateRenderer(window, -1, 0);

int done = 0;
while (!done) {
SDL_Event event;

  while (SDL_PollEvent(&event)) {
switch (event.type) {
   case SDL_WINDOWEVENT:
      switch (event.window.event) {
    case SDL_WINDOWEVENT_CLOSE:
       done = 1;
       break;
    }
      break;
   }
}

  SDL_SetRenderDrawColor(255, 0, 0, 0);
  SDL_RenderClear();
  SDL_RenderPresent();
  }

// Always be sure to clean up
SDL_Quit();
return 0;
}
#endif


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

I had already tried that, as well as trying various other flags settings. It
doesn’t have any effect. (I tried it again just now in case I missed
something.)

I also just updated to the latest ATI Catalyst driver (10.11) and that didn’t
help either.

Below is something I tried just now that makes me think it really is some sort
of uninitialized data problem: first draw a red screen, then pause a second
and redraw the screen as green. The first draw just gives me a black window,
but the second render gives me the green I’d expect. The first set of calls
is failing but reporting no error, but is apparently having some side-effect
that lets the second set of calls work normally.

Eris

int main(int argc, char** argv)
{
if (SDL_Init(SDL_INIT_VIDEO) < 0) return 1;

SDL_Window* window =
SDL_CreateWindow(“SDL_RenderClear”,
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
512, 512,
SDL_WINDOW_SHOWN);

SDL_CreateRenderer(window, -1, SDL_RENDERER_SINGLEBUFFER);

if (SDL_SetRenderDrawColor(255, 0, 0, 0)) printf("%s\n", SDL_GetError());
if (SDL_RenderClear()) printf("%s\n", SDL_GetError());
SDL_RenderPresent();
SDL_Delay(1000);

if (SDL_SetRenderDrawColor(0, 255, 0, 0)) printf("%s\n", SDL_GetError());
if (SDL_RenderClear()) printf("%s\n", SDL_GetError());
SDL_RenderPresent();
SDL_Delay(1000);

SDL_Quit();
return 0;
}On Tuesday 23 November 2010, Alex Barry wrote:

Try doing this:
SDL_CreateRenderer( window, -1, SDL_RENDERER_SINGLEBUFFER );
SDL_SelectRenderer( window );

Either this is an issue with the renderer not being selected, or a problem
with double/triple/x-buffering. If the above code works, awesome, and if
not, let me know and we can do some more troubleshooting.

Take care,
-Alex