Here is a modified version of the program I’m working on.
Thanks,
Chip
#include <iostream.h>
#include <SDL.h>
#include <stdlib.h>
/////////////////////////////////////////////////////
// GLOBALS
/////////////////////////////////////////////////////
#define WIDTH 640
#define HEIGHT 480
#define BPP 32
#define P_SIZE 255
#define SCREEN_SIZE WIDTH*HEIGHT
typedef struct{
SDL_Surface *screen;
SDL_Surface *buffer;
SDL_Surface *bkgrnd;
Uint32 *pixel_buffer;
}GLOBALS;
GLOBALS g;
int init(Uint32 init_flags, Uint32 video_flags){
if(SDL_Init(init_flags) < 0){
cout<<SDL_GetError()<<endl;
return -1;
}
else{
atexit(SDL_Quit);
g.screen = SDL_SetVideoMode(WIDTH, HEIGHT, BPP, video_flags);
if(g.screen == NULL){
cout<<SDL_GetError()<<endl;
return -1;
}
else{
g.buffer = SDL_ConvertSurface(g.screen, g.screen->format, SDL_HWSURFACE);
if(g.buffer == NULL){
cout<<SDL_GetError()<<endl;
return -1;
}
else{
SDL_SetAlpha(g.buffer, SDL_SRCALPHA, 255);
// Am I using this right?
}
g.bkgrnd = SDL_LoadBMP("background.bmp");
if(g.bkgrnd == NULL){
cout << SDL_GetError() << endl;
return -1;
}
}
}
return 0;
}
int draw(){
bool need_lock = false;
g.pixel_buffer = (Uint32 *)g.buffer->pixels;
if(SDL_MUSTLOCK(g.buffer)){
SDL_LockSurface(g.buffer);
need_lock = true;
}
for(int i=0; i < 20000; i++){
g.pixel_buffer[(rand()%WIDTH) + ((rand()%HEIGHT)*WIDTH)] =
SDL_MapRGBA(g.buffer->format, 255,255,255,56);
}
if(need_lock){
SDL_UnlockSurface(g.buffer);
}
SDL_BlitSurface(g.buffer, NULL, g.screen, NULL);
SDL_Flip(g.screen);
return 0;
}
int main(int argc, char * argv){
bool done = false;
SDL_Event event;
cout << "Initializing: ";
if(init(SDL_INIT_VIDEO, SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN) < 0){
return -1;
}
cout << "Done :)\n";
SDL_ShowCursor(0);
SDL_BlitSurface(g.bkgrnd, NULL, g.screen, NULL);
SDL_UpdateRect(g.screen, 0,0,0,0);
SDL_Delay(4000);
cout << "Entering main loop.\n";
while(!done){
while(SDL_PollEvent(&event)){
switch(event.type){
case SDL_QUIT:
done = true;
break;
case SDL_KEYDOWN:
done = true;
break;
default:
break;
}
}
draw();
}
SDL_FreeSurface(g.buffer);
cout << "All done\n";
SDL_Delay(300);
return 0;
}On Friday 25 January 2002 04:22, you wrote:
Chip Collier <@Chip_Collier> wrote:
I’m drawing directly to an offscreen buffer that is 32bits. The surface is
created and if my pointer isn’t NULL I go ahead and SDL_SetAlpha(buffer,
SDL_SRCALPHA, 255). But it only uses per-surface alpha blending when I
blit it to the screen.
please make a complete minimal testcase that we can look at