Dga neomagic problem?

greetings. i am having a lot of fun using sdl - my thanks
to everyone who has worked on it.

however…i am experiencing some problems using the sdl dga
driver on my laptop (sony vaio PCG-505G, neomagic). the
attached program simply draws a grid on the screen. when
using the X driver, or with the dga driver on a different
machine, drawing a grid (e.g. 10 by 10) in fullscreen mode
is fine. but on my laptop, the lower rectangles are not
drawn. or rather, they are drawn too low, which apparently
results in them being drawn on the back buffer - press any
key besides q in the test program to SDL_Flip().

so, does anyone else have this problem or have ideas on what
the cause may be? any help would be hugely appreciated!

adam
-------------- next part --------------
#include <stdlib.h>
#include <stdio.h>

#include <SDL/SDL.h>

void usage()
{
fprintf(stderr, “Usage: dga-problem [-f] \n”);
}

int main(int argc, char *argv[])
{
SDL_VideoInfo *info;
int video_mode_flags;
SDL_Surface *screen;
int width, height;
int rows, cols;
int cell_w, cell_h;
int div_w = 1;
int done;
SDL_Rect rect;
Uint32 color;
int i, j;

argc–;
argv++;
video_mode_flags = SDL_HWSURFACE | SDL_DOUBLEBUF;
while (argc && argv[0][0] == ‘-’) {
if (!strcmp(argv[0], “-f”)) {
video_mode_flags |= SDL_FULLSCREEN;
} else {
usage();
return 1;
}
argc–;
argv++;
}

if (argc != 4) {
usage();
return 1;
}

width = atoi(argv[0]);
height = atoi(argv[1]);
rows = atoi(argv[2]);
cols = atoi(argv[3]);

printf(“Initializing SDL…”);
if (SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, “Unable to init SDL: %s\n”, SDL_GetError());
return 1;
}
printf(“ok\n”);

info = (SDL_VideoInfo *)SDL_GetVideoInfo();
if (info == NULL) {
fprintf(stderr, “Unable to get video info: %s\n”, SDL_GetError());
return 1;
}

printf(“Setting video mode…”);
screen = SDL_SetVideoMode(width, height, 16, video_mode_flags);
if (screen == NULL) {
fprintf(stderr, “Unable to set video mode: %s\n”, SDL_GetError());
return 1;
}
printf(“ok\n”);

cell_w = (screen->w - (cols + 1) * div_w) / cols;
cell_h = (screen->h - (rows + 1) * div_w) / rows;

/* background */
rect.x = 0;
rect.y = 0;
rect.w = width;
rect.h = height;
color = SDL_MapRGB(screen->format, 0, 0, 0);
SDL_FillRect(screen, &rect, color);

color = SDL_MapRGB(screen->format, 255, 255, 255);

/* horizontals */
for (i = 0; i <= rows; i++) {
rect.x = 0;
rect.y = i * (div_w + cell_h);
rect.w = screen->w;
rect.h = div_w;
SDL_FillRect(screen, &rect, color);
}

/* verticals */
for (i = 0; i <= cols; i++) {
rect.x = i * (div_w + cell_w);
rect.y = 0;
rect.w = div_w;
rect.h = screen->h;
SDL_FillRect(screen, &rect, color);
}

SDL_Flip(screen);

done = 0;

while (!done) {
SDL_Event event;

while (SDL_PollEvent(&event)) {
  switch (event.type) {

    case SDL_KEYDOWN:
      if (event.key.keysym.sym == SDLK_q) {
        done = 1;
        break;
      }
      SDL_Flip(screen);
      break;

    case SDL_QUIT:
      done = 1;
      break;

    default:
        break;
  }
}

}

SDL_Quit();
return 0;
}

fyi, i was able to work around this issue by using blits
instead of SDL_FillRect. that is, i draw the rects onto my
own surface and blit to both the back and front screen
surfaces so i can flip between them.

adam

Quoting Adam Marks (@Adam_Marks):> greetings. i am having a lot of fun using sdl - my thanks

to everyone who has worked on it.

however…i am experiencing some problems using the sdl dga
driver on my laptop (sony vaio PCG-505G, neomagic). the
attached program simply draws a grid on the screen. when
using the X driver, or with the dga driver on a different
machine, drawing a grid (e.g. 10 by 10) in fullscreen mode
is fine. but on my laptop, the lower rectangles are not
drawn. or rather, they are drawn too low, which apparently
results in them being drawn on the back buffer - press any
key besides q in the test program to SDL_Flip().

so, does anyone else have this problem or have ideas on what
the cause may be? any help would be hugely appreciated!

adam

#include <stdlib.h>
#include <stdio.h>

#include <SDL/SDL.h>

void usage()
{
fprintf(stderr, “Usage: dga-problem [-f] \n”);
}

int main(int argc, char *argv[])
{
SDL_VideoInfo *info;
int video_mode_flags;
SDL_Surface *screen;
int width, height;
int rows, cols;
int cell_w, cell_h;
int div_w = 1;
int done;
SDL_Rect rect;
Uint32 color;
int i, j;

argc–;
argv++;
video_mode_flags = SDL_HWSURFACE | SDL_DOUBLEBUF;
while (argc && argv[0][0] == ‘-’) {
if (!strcmp(argv[0], “-f”)) {
video_mode_flags |= SDL_FULLSCREEN;
} else {
usage();
return 1;
}
argc–;
argv++;
}

if (argc != 4) {
usage();
return 1;
}

width = atoi(argv[0]);
height = atoi(argv[1]);
rows = atoi(argv[2]);
cols = atoi(argv[3]);

printf(“Initializing SDL…”);
if (SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, “Unable to init SDL: %s\n”, SDL_GetError());
return 1;
}
printf(“ok\n”);

info = (SDL_VideoInfo *)SDL_GetVideoInfo();
if (info == NULL) {
fprintf(stderr, “Unable to get video info: %s\n”, SDL_GetError());
return 1;
}

printf(“Setting video mode…”);
screen = SDL_SetVideoMode(width, height, 16, video_mode_flags);
if (screen == NULL) {
fprintf(stderr, “Unable to set video mode: %s\n”, SDL_GetError());
return 1;
}
printf(“ok\n”);

cell_w = (screen->w - (cols + 1) * div_w) / cols;
cell_h = (screen->h - (rows + 1) * div_w) / rows;

/* background */
rect.x = 0;
rect.y = 0;
rect.w = width;
rect.h = height;
color = SDL_MapRGB(screen->format, 0, 0, 0);
SDL_FillRect(screen, &rect, color);

color = SDL_MapRGB(screen->format, 255, 255, 255);

/* horizontals */
for (i = 0; i <= rows; i++) {
rect.x = 0;
rect.y = i * (div_w + cell_h);
rect.w = screen->w;
rect.h = div_w;
SDL_FillRect(screen, &rect, color);
}

/* verticals */
for (i = 0; i <= cols; i++) {
rect.x = i * (div_w + cell_w);
rect.y = 0;
rect.w = div_w;
rect.h = screen->h;
SDL_FillRect(screen, &rect, color);
}

SDL_Flip(screen);

done = 0;

while (!done) {
SDL_Event event;

while (SDL_PollEvent(&event)) {
  switch (event.type) {

    case SDL_KEYDOWN:
      if (event.key.keysym.sym == SDLK_q) {
        done = 1;
        break;
      }
      SDL_Flip(screen);
      break;

    case SDL_QUIT:
      done = 1;
      break;

    default:
        break;
  }
}

}

SDL_Quit();
return 0;
}