Hello,

I have rewrite the program to SDL.
glClear is ok, but there is the same problem with the XOR logic op for 
rubber/rectangles.
With export LIBGL_ALWAYS_INDIRECT=1, all is ok too.

On Tue, 2 Jul 2002 09:18:21 -0700 (PDT)
Graham Hay <[EMAIL PROTECTED]> wrote:

> Hello all,
> I've been following the mach64 efforts closely and it seemed
> like a good time to try a binary snapshot. Very impressive!
> Thanks to all involved.
> 
> I did find a problem running an OpenGL app I wrote for work.
> It seems that when I use the XOR logic op for rubber
> banded lines/rectangles that it doesn't erase the previously
> drawn pixels. They get set to something which looks like an
> XOR would, but it stays that way. Maybe the logic op is set
> wrong?
> 
> I wrote a smaller test program for this in C which you can
> find here:
> 
> http://www.tardis.ed.ac.uk/~gnh/mach64/xor_test.c
> 
> It should show you what I'm talking about. Also, when the
> window first pops up the glClear isn't coincident with the
> top left of the window as if the viewport wasn't right,
> although the rectangle is in the right place. Another
> clear via expose does affect the whole window, but if I
> put the window half off screen and drag it back into the
> middle, only parts of it are cleared.
> 
> This all works using software rendering,
> using export LIBGL_ALWAYS_INDIRECT=1 has no problems nor
> no nvidias drivers on my other machine for example.
> 
> I hope this helps - it may not be quake III, but at least
> theres some code to look at and I know some of you aren't
> just into games.
> 
> system is a PIII dell laptop, 8MB mach64:
> ATI Technologies Inc Rage Mobility P/M AGP 2x (rev 64) (prog-if 00 [VGA])
> 
> Thanks again for all your work,
> Graham

-- 
Valéry Febvre / Easter-Eggs              Spécialiste GNU/Linux
44-46 rue de l'Ouest  -  75014 Paris  -  France -  Métro Gaité
Phone: +33 (0) 1 43 35 00 37    -   Fax: +33 (0) 1 43 35 00 76
mailto:[EMAIL PROTECTED]  -   http://www.easter-eggs.com
9E9C2B24  -  91EB 2878 A4BF D149 90C7 4090 9415 8B9F 9E9C 2B24
/*
 * Febvre Val�ry, 2002.
 * SDL OpenGL / XOR logic op test program
 *
 * gcc -Wall -lGL -lGLU -lSDL -lpthread -o xor_test_sdl xor_test_sdl.c
 */

#include <SDL/SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>

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

typedef enum { Released, Pressed, Drawing } ButtonState;

typedef struct {
  short x, y;
} XPoint;

typedef struct {
  ButtonState state;
  XPoint start, prev;
} mouseState;

static void quit(int code) {
    SDL_Quit( );
    exit(code);
}

static void handle_key_down(SDL_keysym* keysym) {
    switch( keysym->sym ) {
    case SDLK_ESCAPE:
        quit( 0 );
        break;
    default:
        break;
    }
}

static void process_events(mouseState *mouse, int width, int height) {
    SDL_Event event;

    while(SDL_PollEvent(&event)) {
        switch(event.type) {
        case SDL_KEYDOWN:
            handle_key_down(&event.key.keysym);
            break;
        case SDL_QUIT:
            quit(0);
            break;
	case SDL_MOUSEMOTION:
	  if (mouse->state == Drawing) {
	    /* erase previous */
	    glBegin(GL_LINE_STRIP);
	    glVertex2i(mouse->start.x, mouse->start.y);
	    glVertex2i(mouse->prev.x, mouse->prev.y);
	    glEnd();
	    
	    /* this *will* be prev */
	    mouse->prev.x = event.button.x;
	    mouse->prev.y = height - event.button.y - 1;
	    
	    /* draw new */
	    glBegin(GL_LINE_STRIP);
	    glVertex2i(mouse->start.x, mouse->start.y);
	    glVertex2i(mouse->prev.x, mouse->prev.y);
	    glEnd();
	    glFlush();
	  }
	  else if (mouse->state == Pressed) {
	    mouse->state = Drawing;
	    
	    glColor3f(1.0f, 1.0f, 1.0f);
	    
	    glPushAttrib(GL_COLOR_BUFFER_BIT);
	    glDrawBuffer(GL_FRONT);
	    glEnable(GL_COLOR_LOGIC_OP);
	    glLogicOp(GL_XOR);
	    
	    /* this *will* be prev */
	    mouse->prev.x = event.button.x;
	    mouse->prev.y = height - event.button.y - 1;
	    
	    /* draw first */
	    glBegin(GL_LINE_STRIP);
	    glVertex2d(mouse->start.x, mouse->start.y);
	    glVertex2d(mouse->prev.x, mouse->prev.y);
	    glEnd();
	    glFlush();
	  }
	  break;
	case SDL_MOUSEBUTTONDOWN: 
	  mouse->state = Pressed;
	  mouse->start.x = event.button.x;
	  mouse->start.y = height - event.button.y - 1;
	  mouse->prev = mouse->start;
	  break;
	case SDL_MOUSEBUTTONUP:
	  if (mouse->state == Drawing) {
	    /* erase previous */
	    glBegin(GL_LINE_STRIP);
	    glVertex2i(mouse->start.x, mouse->start.y);
	    glVertex2i(mouse->prev.x, mouse->prev.y);
	    glEnd();
	    
	    glFlush();
	    glPopAttrib();
	  }
	  mouse->state = Released;
	  break;
	default:
	  break;
        }
    }
}

static void draw_screen(void) {
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glColor3f(0.0, 1.0f, 1.0f);
  glRecti(100, 100, 200, 200);
  SDL_GL_SwapBuffers();
}

static void setup_opengl(int width, int height) {
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  
  glOrtho(0.0, width, 0.0, height, -1.0, 1.0);
  glTranslatef(0.375f, 0.375f, 0.0f);
  
  glClearDepth(1.0f);
  glClearColor( 1.0f, 0.0f, 0.0f, 1.0f); /* red */
}

int main(int argc, char* argv[]) {
  mouseState* mouse = (mouseState*) malloc(sizeof(mouseState));
  const SDL_VideoInfo* info = NULL;
  int width = 0;
  int height = 0;
  int bpp = 0;
  int flags = 0;
  
  mouse->state = Released;

  if(SDL_Init(SDL_INIT_VIDEO) < 0) {
    fprintf(stderr, "Video initialization failed: %s\n",
	    SDL_GetError());
    quit(1);
  }
  info = SDL_GetVideoInfo();
  if(!info) {
    fprintf(stderr, "Video query failed: %s\n",
	    SDL_GetError());
    quit(1);
  }
  
  width = 250;
  height = 250;
  bpp = info->vfmt->BitsPerPixel;
  
  flags = SDL_OPENGL;
  if(SDL_SetVideoMode(width, height, bpp, flags) == 0) {
    fprintf( stderr, "Video mode set failed: %s\n", SDL_GetError());
    quit(1);
  }
  
  setup_opengl(width, height);
  draw_screen();
  
  while(1) {
    process_events(mouse, width, height);
  }
  return 0;
}

Attachment: msg05677/pgp00000.pgp
Description: PGP signature

Reply via email to