It seems SDL exchanges R & B channels

Dear all,

In the test code, I wanna show a red window but it turn out to be blue.
What’s wrong?

#include <stdlib.h>
#if defined(_MSC_VER)
#include “SDL.h”
#else
#include “SDL/SDL.h”
#endif

SDL_Surface *screen;

void render()
{
// Lock surface if needed
if (SDL_LockSurface(screen) < 0)
return;

 // Ask SDL for the time in milliseconds
 int tick = SDL_GetTicks();

 // Declare a couple of variables
 int i, j, b, yofs, ofs;
 unsigned char *pc;
 unsigned long *pl;

 // Draw to screen
 Uint32 color = SDL_MapRGB(screen->format, 255, 0, 0);
 printf("color:0x%08x\n", color);

 yofs = 0;
 for (i = 0; i < 480; i++)
 {
     ofs = yofs;
     for (j = 0; j < 640; j++)
     {
         ((unsigned int*)screen->pixels)[ofs++] = color;
     }
     yofs += screen->pitch / 4;
 }

 // Unlock if needed
 if (SDL_MUSTLOCK(screen))
     SDL_UnlockSurface(screen);

 // Tell SDL to update the whole screen
 SDL_UpdateRect(screen, 0, 0, 640, 480);

}

// Entry point
int main(int argc, char *argv[])
{
// Initialize SDL’s subsystems - in this case, only video.
if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
{
fprintf(stderr, “Unable to init SDL: %s\n”, SDL_GetError());
exit(1);
}

 // Register SDL_Quit to be called at exit; makes sure things are
 // cleaned up when we quit.
 atexit(SDL_Quit);

 // Attempt to create a 640x480 window with 32bit pixels.
 screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);

 // If we fail, return error.
 if ( screen == NULL )
 {
     fprintf(stderr, "Unable to set 640x480 video: %s\n",  

SDL_GetError());
exit(1);
}

 // Main loop: loop forever.
 while (1)
 {
     // Render stuff
     render();

     // Poll for events, and handle the ones we care about.
     SDL_Event event;
     while (SDL_PollEvent(&event))
     {
         switch (event.type)
         {
         case SDL_KEYDOWN:
             break;
         case SDL_KEYUP:
             // If escape is pressed, return (and thus, quit)
             if (event.key.keysym.sym == SDLK_ESCAPE)
                 return 0;
             break;
         case SDL_QUIT:
             return(0);
         }
     }
 }
 return 0;

}

I compile and run the program on i686 GNU/linux Red Hat Enterprise Linux
ES release 4, the installed SDL version is SDL-1.2.7-8, the GUI
environment is VNC+icewm.–
Using Opera’s revolutionary e-mail client: http://www.opera.com/mail/
-------------- next part --------------
A non-text attachment was scrubbed…
Name: test.c
Type: application/octet-stream
Size: 2253 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20080226/caf7505c/attachment.obj

In the test code, I wanna show a red window but it turn out to be blue.

Sounds like a bug with SDL’s handling of VNC, it works fine here.

-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

Hey,

I’m not sure what’s wrong with your pixel loop, but be careful about the types you use. ‘unsigned int’ should instead be SDL’s ‘Uint32’ type if your particular surface is 32-bit. Also, you’re not guaranteed to have gotten the 32 bits that you asked for. You could check for that or instead use a function that handles pixels for all of the standard bit depths (email me back if you’d like my copy of that). Here’s the line I use for setting a 32-bit pixel in case it helps:
*((Uint32 )surface->pixels + ysurface->pitch/4 + x) = color;
If you’re just trying to fill the surface with color, consider using SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 0, 0));

See ya,
Jonny D> To: sdl at libsdl.org

From: alex.chenhl at gmail.com
Date: Tue, 26 Feb 2008 16:03:13 +0800
Subject: [SDL] It seems SDL exchanges R & B channels

Dear all,

In the test code, I wanna show a red window but it turn out to be blue.
What’s wrong?

#include <stdlib.h>
#if defined(_MSC_VER)
#include “SDL.h”
#else
#include “SDL/SDL.h”
#endif

SDL_Surface *screen;

void render()
{
// Lock surface if needed
if (SDL_LockSurface(screen) < 0)
return;

 // Ask SDL for the time in milliseconds
 int tick = SDL_GetTicks();

 // Declare a couple of variables
 int i, j, b, yofs, ofs;
 unsigned char *pc;
 unsigned long *pl;

 // Draw to screen
 Uint32 color = SDL_MapRGB(screen->format, 255, 0, 0);
 printf("color:0x%08x\n", color);

 yofs = 0;
 for (i = 0; i < 480; i++)
 {
     ofs = yofs;
     for (j = 0; j < 640; j++)
     {
         ((unsigned int*)screen->pixels)[ofs++] = color;
     }
     yofs += screen->pitch / 4;
 }

 // Unlock if needed
 if (SDL_MUSTLOCK(screen))
     SDL_UnlockSurface(screen);

 // Tell SDL to update the whole screen
 SDL_UpdateRect(screen, 0, 0, 640, 480);

}

// Entry point
int main(int argc, char *argv[])
{
// Initialize SDL’s subsystems - in this case, only video.
if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
{
fprintf(stderr, “Unable to init SDL: %s\n”, SDL_GetError());
exit(1);
}

 // Register SDL_Quit to be called at exit; makes sure things are
 // cleaned up when we quit.
 atexit(SDL_Quit);

 // Attempt to create a 640x480 window with 32bit pixels.
 screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);

 // If we fail, return error.
 if ( screen == NULL )
 {
     fprintf(stderr, "Unable to set 640x480 video: %s\n",  

SDL_GetError());
exit(1);
}

 // Main loop: loop forever.
 while (1)
 {
     // Render stuff
     render();

     // Poll for events, and handle the ones we care about.
     SDL_Event event;
     while (SDL_PollEvent(&event))
     {
         switch (event.type)
         {
         case SDL_KEYDOWN:
             break;
         case SDL_KEYUP:
             // If escape is pressed, return (and thus, quit)
             if (event.key.keysym.sym == SDLK_ESCAPE)
                 return 0;
             break;
         case SDL_QUIT:
             return(0);
         }
     }
 }
 return 0;

}

I compile and run the program on i686 GNU/linux Red Hat Enterprise Linux
ES release 4, the installed SDL version is SDL-1.2.7-8, the GUI
environment is VNC+icewm.


Using Opera’s revolutionary e-mail client: http://www.opera.com/mail/


Need to know the score, the latest news, or you need your Hotmail?-get your “fix”.
http://www.msnmobilefix.com/Default.aspx

*((Uint32 )surface->pixels + ysurface->pitch/4 + x) = color;

I tried, but the result was same. Could you help me to test the code if
you have a linux pc?On Tue, 26 Feb 2008 21:10:53 +0800, Jonathan Dearborn wrote:


Using Opera’s revolutionary e-mail client: http://www.opera.com/mail/

In the test code, I wanna show a red window but it turn out to be blue.

Sounds like a bug with SDL’s handling of VNC, it works fine here.

-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

Sam, Thank’s a lot!
I will try to find a server with a local monitor attached to test, you
know that the servers are always locked in the secret chamber:)
Could you give me the info about your environment?On Tue, 26 Feb 2008 20:13:51 +0800, Sam Lantinga wrote:


Using Opera’s revolutionary e-mail client: http://www.opera.com/mail/

Sam, Thank’s a lot!
I will try to find a server with a local monitor attached to test, you
know that the servers are always locked in the secret chamber:)
Could you give me the info about your environment?

Sure. I tested with Mac OS X, running on a MacBook.

-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

Hi Sam,

I test the code through Xwin32(like exceed), and it’s OK with the color.
So you are right, it’s a VNC related bug. But I dont understand why other
app’s color seems ok? Is it related with SDL, do you think so?

Thanks for your insight, it save me a lot of time. But I dont know how to
fix this issue. I love VNC, because our network disconnected and
re-connected frequently due to some problem of intranet, with VNC I could
simply regain all my desktop when reconnected. Do you have any idea where
the bug report should go?On Tue, 26 Feb 2008 22:55:40 +0800, Sam Lantinga wrote:

Sam, Thank’s a lot!
I will try to find a server with a local monitor attached to test, you
know that the servers are always locked in the secret chamber:)
Could you give me the info about your environment?

Sure. I tested with Mac OS X, running on a MacBook.

-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment


Using Opera’s revolutionary e-mail client: http://www.opera.com/mail/

Hi Sam,

I checked the vncserver setting then I set the “-depth” option to 24,
which is default to 16, then the issue gone. Does it indicate there is a
bug in VNC when convert input RGB888 to output RGB565?On Fri, 29 Feb 2008 11:13:06 +0800, Alex Chen <@Alex_Chen> wrote:

On Tue, 26 Feb 2008 22:55:40 +0800, Sam Lantinga wrote:

Hi Sam,

I test the code through Xwin32(like exceed), and it’s OK with the color.
So you are right, it’s a VNC related bug. But I dont understand why other
app’s color seems ok? Is it related with SDL, do you think so?

Thanks for your insight, it save me a lot of time. But I dont know how to
fix this issue. I love VNC, because our network disconnected and
re-connected frequently due to some problem of intranet, with VNC I could
simply regain all my desktop when reconnected. Do you have any idea where
the bug report should go?

Sam, Thank’s a lot!
I will try to find a server with a local monitor attached to test, you
know that the servers are always locked in the secret chamber:)
Could you give me the info about your environment?

Sure. I tested with Mac OS X, running on a MacBook.

-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment


Using Opera’s revolutionary e-mail client: http://www.opera.com/mail/