// Initialize the window for rendering.
void vtkOSMesaRenderWindow::WindowInitialize (void)
{
  TraceBegin("vtkOSMesaRenderWindow::WindowInitialize");

  int width = this->Size[0];
  int height = this->Size[1];
  this->DoubleBuffer = 0;
  if (!this->Internal->OffScreenWindow)
    {
    this->Internal->OffScreenWindow = vtkOSMesaCreateWindow(width,height);
    this->Size[0] = width;
    this->Size[1] = height;      
    }    
  this->Internal->OffScreenContextId = OSMesaCreateContext(GL_RGBA, NULL);

  this->MakeCurrent();
  this->Mapped = 0;

  // tell our renderers about us
  vtkRenderer* ren;
  for (this->Renderers->InitTraversal(); 
       (ren = this->Renderers->GetNextItem());)
    {
    ren->SetRenderWindow(0);
    ren->SetRenderWindow(this);
    }

  this->OpenGLInit();
  glAlphaFunc(GL_GREATER,0);

  TraceEnd("vtkOSMesaRenderWindow::WindowInitialize");
}
Exemplo n.º 2
0
GLboolean glewCreateContext (struct createParams* params)
{
  GLenum format = OSMESA_RGBA;
  GLsizei height = OSM_HEIGHT;
  GLsizei width = OSM_WIDTH;
  GLenum type = GL_UNSIGNED_BYTE;
  void * buffer_pointer = (void *)(&(pixels[0]));
  /*
  GLint depthBits = 24;
  GLint stencilBits = 8;
  GLint accumBits = 8;
  OSMesaContext sharelist = NULL;
  */
  (void)(params);

  /*ctx = OSMesaCreateContextExt( format, depthBits, stencilBits, accumBits, sharelist );*/
  ctx = OSMesaCreateContext( format, NULL );
  if (!ctx) {
    return GL_TRUE;
  }
  if (!OSMesaMakeCurrent( ctx, buffer_pointer, type, width, height )) {
    return GL_TRUE;
  }
  return GL_FALSE;
}
Exemplo n.º 3
0
void main()
{
	unsigned char *data;
	allocDoubleBuffer_vbe();
	
	sys_VBEstart();
	SCREEN =sys_giveSCREEN();
	
    allocDoubleBuffer_vbe();
   	memset(SCREEN, 10, 1024*768*4);
   		
    OSMesaContext gl_ctx = OSMesaCreateContext(OSMESA_BGRA, NULL);
	if(!OSMesaMakeCurrent(gl_ctx, DOUBLEBUFFER_vbe, GL_UNSIGNED_BYTE, 1024,768))
		sys_reboot();
		
	OSMesaPixelStore(OSMESA_Y_UP, 0);
	reshape(1024,768);
	
	init();
	
	int i;
	for(i = 0; i < 20000; i++)
	{
		angle += 6;
		draw();
		SwapBuffers_vbe();
	}
	fps(); 
}
Exemplo n.º 4
0
CAMLprim value
ml_osmesacreatecontext( value _format,
                        value ml_sharelist )
{
    OSMesaContext ctx;
    OSMesaContext sharelist;
    GLenum format;

    if (Is_long(ml_sharelist))
        sharelist = NULL;
    else
        sharelist = (OSMesaContext) Field(ml_sharelist,0);

    switch (Int_val(_format)) {
        case 0: format = OSMESA_COLOR_INDEX; break;
        case 1: format = OSMESA_RGBA; break;
        case 2: format = OSMESA_BGRA; break;
        case 3: format = OSMESA_ARGB; break;
        case 4: format = OSMESA_RGB; break;
        case 5: format = OSMESA_BGR; break;
    }

    ctx = OSMesaCreateContext( format, sharelist );

    if (!ctx)
        caml_failwith("osMesaCreateContext");

    return (value) ctx;
}
Exemplo n.º 5
0
SkMesaGLContext::SkMesaGLContext()
    : fContext(static_cast<Context>(NULL))
    , fImage(NULL) {
    GR_STATIC_ASSERT(sizeof(Context) == sizeof(OSMesaContext));

    /* Create an RGBA-mode context */
#if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305
    /* specify Z, stencil, accum sizes */
    fContext = (Context)OSMesaCreateContextExt(OSMESA_BGRA, 0, 0, 0, NULL);
#else
    fContext = (Context)OSMesaCreateContext(OSMESA_BGRA, NULL);
#endif
    if (!fContext) {
        SkDebugf("OSMesaCreateContext failed!\n");
        this->destroyGLContext();
        return;
    }
    // Allocate the image buffer
    fImage = (GrGLubyte *) sk_malloc_throw(gBOGUS_SIZE * gBOGUS_SIZE *
                                           4 * sizeof(GrGLubyte));
    if (!fImage) {
        SkDebugf("Alloc image buffer failed!\n");
        this->destroyGLContext();
        return;
    }

    // Bind the buffer to the context and make it current
    if (!OSMesaMakeCurrent((OSMesaContext)fContext,
                           fImage,
                           GR_GL_UNSIGNED_BYTE,
                           gBOGUS_SIZE,
                           gBOGUS_SIZE)) {
        SkDebugf("OSMesaMakeCurrent failed!\n");
        this->destroyGLContext();
        return;
    }

    SkAutoTUnref<const GrGLInterface> gl(GrGLCreateMesaInterface());
    if (NULL == gl.get()) {
        SkDebugf("Could not create GL interface!\n");
        this->destroyGLContext();
        return;
    }

    if (!gl->validate()) {
        SkDebugf("Could not validate GL interface!\n");
        this->destroyGLContext();
        return;
    }

    this->init(gl.detach());
}
Exemplo n.º 6
0
static void *osmesa_ctx_init(video_frame_info_t *video_info, void *video_driver)
{
#ifdef HAVE_OSMESA_CREATE_CONTEXT_ATTRIBS
   const int attribs[] = {
      OSMESA_FORMAT, g_osmesa_format,
      OSMESA_DEPTH_BITS, 0,
      OSMESA_STENCIL_BITS, 0,
      OSMESA_ACCUM_BITS, 0,
      OSMESA_PROFILE, g_osmesa_profile,
      OSMESA_CONTEXT_MAJOR_VERSION, g_osmesa_major,
      OSMESA_CONTEXT_MINOR_VERSION, g_osmesa_minor,
      0, 0
   };
#endif
   gfx_ctx_osmesa_data_t *osmesa = (gfx_ctx_osmesa_data_t*)
      calloc(1, sizeof(gfx_ctx_osmesa_data_t));

   if (!osmesa)
      goto error;

#ifdef HAVE_OSMESA_CREATE_CONTEXT_ATTRIBS
   osmesa->ctx = OSMesaCreateContextAttribs(attribs, NULL);
#endif

#ifdef HAVE_OSMESA_CREATE_CONTEXT_EXT
   if (!osmesa->ctx)
      osmesa->ctx = OSMesaCreateContextExt(g_osmesa_format, 0, 0, 0, NULL);
#endif

   if (!osmesa->ctx)
   {
#if defined(HAVE_OSMESA_CREATE_CONTEXT_ATTRIBS) || defined(HAVE_OSMESA_CREATE_CONTEXT_EXT)
      RARCH_WARN("[osmesa]: Falling back to standard context creation.\n");
#endif
      osmesa->ctx = OSMesaCreateContext(g_osmesa_format, NULL);
   }

   if (!osmesa->ctx)
      goto error;

   osmesa->pixsize = g_osmesa_bpp;

   return osmesa;

error:
   if (osmesa)
      free(osmesa);
   RARCH_WARN("[omesa]: Failed to initialize the context driver.\n");
   return NULL;
}
Exemplo n.º 7
0
GLboolean glewCreateContext (struct createParams *params)
{
  ctx = OSMesaCreateContext(OSMESA_RGBA, NULL);
  if (NULL == ctx) return GL_TRUE;
  if (NULL == osmPixels)
  {
    osmPixels = (GLubyte *) calloc(osmWidth*osmHeight*4, 1);
  }
  if (!OSMesaMakeCurrent(ctx, osmPixels, GL_UNSIGNED_BYTE, osmWidth, osmHeight))
  {
      return GL_TRUE;
  }
  return GL_FALSE;
}
Exemplo n.º 8
0
GLboolean CreateContext (GLContext* ctx)
{
  GLenum format = OSMESA_RGBA;
  GLsizei height = OSM_HEIGHT;
  GLsizei width = OSM_WIDTH;
  GLenum type = GL_UNSIGNED_BYTE;
  GLubyte pixels[OSM_WIDTH*OSM_HEIGHT*OSM_BYTES_PER_PIXEL];
  void * buffer_pointer = (void *)(&(pixels[0]));
  ctx->ctx = OSMesaCreateContext( format, NULL );
  if (!ctx->ctx) return GL_TRUE;
  if (!OSMesaMakeCurrent( ctx->ctx, buffer_pointer, type, width, height )) {
    return GL_TRUE;
  }
  return GL_FALSE;
}
Exemplo n.º 9
0
static GLboolean CreateContext(GLContext* ctx)
{
	if (NULL == ctx) return GL_TRUE;
	ctx->ctx = OSMesaCreateContext(OSMESA_RGBA, NULL);
	if (NULL == ctx->ctx) return GL_TRUE;
	if (NULL == osmPixels)
	{
		osmPixels = (GLubyte *)calloc(osmWidth*osmHeight * 4, 1);
	}
	if (!OSMesaMakeCurrent(ctx->ctx, osmPixels, GL_UNSIGNED_BYTE, osmWidth, osmHeight))
	{
		return GL_TRUE;
	}
	return GL_FALSE;
}
Exemplo n.º 10
0
OSGLContext_osmesa::OSGLContext_osmesa(const FramebufferConfig& pixelFormatAttrs,
                                       int /*major*/,
                                       int /*minor*/,
                                       bool /*coreProfile*/,
                                       const GLRendererID& rendererID,
                                       const OSGLContext_osmesa* shareContex)
: _imp(new OSGLContext_osmesaPrivate())
{
    GLenum format = GL_RGBA;
    int depthBits = pixelFormatAttrs.depthBits;
    int stencilBits = pixelFormatAttrs.stencilBits;
    int accumBits = pixelFormatAttrs.accumRedBits + pixelFormatAttrs.accumGreenBits + pixelFormatAttrs.accumBlueBits + pixelFormatAttrs.accumAlphaBits;
    /* Create an RGBA-mode context */
#if defined(OSMESA_GALLIUM_DRIVER) && (OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 1102)
    /* specify Z, stencil, accum sizes */
    {
        int cpuDriver = rendererID.renderID;

        int attribs[100], n = 0;

        attribs[n++] = OSMESA_FORMAT;
        attribs[n++] = format;
        attribs[n++] = OSMESA_DEPTH_BITS;
        attribs[n++] = depthBits;
        attribs[n++] = OSMESA_STENCIL_BITS;
        attribs[n++] = stencilBits;
        attribs[n++] = OSMESA_ACCUM_BITS;
        attribs[n++] = accumBits;
        attribs[n++] = OSMESA_GALLIUM_DRIVER;
        attribs[n++] = (int)cpuDriver;
        attribs[n++] = 0;
        _imp->ctx = OSMesaCreateContextAttribs( attribs, shareContex ? shareContex->_imp->ctx : 0);
    }
#else
    Q_UNUSED(rendererID);
#if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305
    /* specify Z, stencil, accum sizes */
    _imp->ctx = OSMesaCreateContextExt( format, depthBits, stencilBits, accumBits, shareContex ? shareContex->_imp->ctx : 0);
#else
    _imp->ctx = OSMesaCreateContext( format, shareContex ? shareContex->_imp->ctx : 0);
#endif
#endif
    
    if (!_imp->ctx) {
        throw std::runtime_error("OSMesaCreateContext failed");
    }
}
Exemplo n.º 11
0
const GrGLInterface* SkMesaGLContext::createGLContext() {
    /* Create an RGBA-mode context */
#if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305
    /* specify Z, stencil, accum sizes */
    fContext = (Context)OSMesaCreateContextExt(OSMESA_BGRA, 0, 0, 0, NULL);
#else
    fContext = (Context)OSMesaCreateContext(OSMESA_BGRA, NULL);
#endif
    if (!fContext) {
        SkDebugf("OSMesaCreateContext failed!\n");
        this->destroyGLContext();
        return NULL;
    }
    // Allocate the image buffer
    fImage = (GrGLubyte *) sk_malloc_throw(gBOGUS_SIZE * gBOGUS_SIZE *
                                           4 * sizeof(GrGLubyte));
    if (!fImage) {
        SkDebugf("Alloc image buffer failed!\n");
        this->destroyGLContext();
        return NULL;
    }
    
    // Bind the buffer to the context and make it current
    if (!OSMesaMakeCurrent((OSMesaContext)fContext, 
                           fImage, 
                           GR_GL_UNSIGNED_BYTE, 
                           gBOGUS_SIZE, 
                           gBOGUS_SIZE)) {
        SkDebugf("OSMesaMakeCurrent failed!\n");
        this->destroyGLContext();
        return NULL;
    }
    
    const GrGLInterface* interface = GrGLCreateMesaInterface();
    if (!interface) {
        SkDebugf("Could not create GL interface!\n");
        this->destroyGLContext();
        return NULL;
    }
    return interface;
    
}
Exemplo n.º 12
0
int main(int argc, char** argv){

	{
		PreInitEvent evt;
		evt.argc = argc;
		evt.argv = argv;
		AppEventFunction(evt);
	}

	OSMesaContext ctx = OSMesaCreateContext(OSMESA_BGRA, NULL);
	
	imgBuffer = (unsigned char*)malloc(width*height*4);
	
	OSMesaMakeCurrent(ctx, imgBuffer, GL_UNSIGNED_BYTE, width, height);
	
	InitGlExts();

	AppEventFunction(PostInitEvent());
	
	bool success = true;
	{
		UpdateEvent evt;
		evt.shouldContinue = &success;
		AppEventFunction(evt);
	}

	if (!success){
		AppEventFunction(ShutDownEvent());
		OSMesaDestroyContext(ctx);
		free(imgBuffer);

		return -1;
	}

	AppEventFunction(ShutDownEvent());
	OSMesaDestroyContext(ctx);
	free(imgBuffer);
	
	return 0;
}
Exemplo n.º 13
0
int main(int argc, char *argv[]) {

    int             ret;
    int             cnt;
    struct timespec tsp;
    long            next_frame;


    gl_ctx = OSMesaCreateContext(OSMESA_BGRA, NULL);

    ace_connection = ace_connect("GlxGears");
    width = 400;
    height = 300;
    gl_win = ace_win_create(ace_connection, 1, 0, 0);
    ace_buffer = ace_buffer_create(ace_connection, 1024 * 768 * sizeof(uint32_t));
    //ace_win_clear(gl_win, 0x000000);
    //ace_buffer_damage(gl_win, ace_buffer, -1, -1, -1, -1, -1);

    ace_win_update(gl_win, ace_buffer, width, height, width*4);
    ace_win_show(gl_win);

    ret = OSMesaMakeCurrent(gl_ctx, ace_buffer->pixel_buf, GL_UNSIGNED_BYTE, width, height);
    OSMesaPixelStore( OSMESA_Y_UP , GL_FALSE );
    reshape(width, height);

    init();

    clock_gettime(CLOCK_REALTIME, &tsp);
    next_frame = TIMESPEC_TO_TICK(&tsp);
    while (1) {
        //ace_win_clear(gl_win, 0x80000000);
        memset(ace_buffer->pixel_buf, 0, 1024 * 768 * sizeof(uint32_t));
        draw();
        /* Now wait for the next frame time */
        while (1) {
            long    curr_time;
            clock_gettime(CLOCK_REALTIME, &tsp);
            curr_time = TIMESPEC_TO_TICK(&tsp);
            if (curr_time > next_frame)
                break;
            switch (get_event()) {
                case ACE_KEY_RIGHT:
                    view_roty += 0.5;
                    break;
                case ACE_KEY_LEFT:
                    view_roty -= 0.5;
                    break;
                case ACE_KEY_UP:
                    view_rotx += 0.5;
                    break;
                case ACE_KEY_DOWN:
                    view_rotx -= 0.5;
                    break;
                default:
                    break;
            }
        }
        ace_win_update(gl_win, ace_buffer, width, height, width);
//        ace_win_damage(gl_win, -1, -1, -1, -1);
        next_frame += 40000000;
        angle += 1;
        clock_gettime(CLOCK_REALTIME, &tsp);
        if (++cnt == 1000) {
            anvil_syslog(0, "TIME %ld %ld\n", tsp.tv_sec, tsp.tv_nsec);
            cnt = 0;
        }
//        usleep(40000);
    }
    anvil_syslog(0, "All done\n");

    while (1)
        sleep(1);
}
Exemplo n.º 14
0
    int
main(int argc, char *argv[])
{
    OSMesaContext ctx;
    void *buffer;

    if (argc < 3) {
        fprintf(stderr, "Usage:\n");
        fprintf(stderr, "  render modelname pngname [width height] [camx camy camz] [centerx centerz centerz] [upx upy upz] [fovy]\n");
        fprintf(stderr, "Default: width=%d height=%d cam=[%0.4f %0.4f %0.4f] center=[%0.4f %0.4f %0.4f] up=[%0.4f %0.4f %0.4f] fovy=%0.4f\n", Width, Height, camx, camy, camz, centerx, centery, centerz, upx, upy, upz, fovy);
        return 0;
    }

    modelname = argv[1];
    pngname = argv[2];

    if (argc >= 5) {
        Width = atoi(argv[3]);
        Height = atoi(argv[4]);
    }

    if (argc >= 8) {
        camx = atoi(argv[5]);
        camy = atoi(argv[6]);
        camz = atoi(argv[7]);
    }

    if (argc >= 11) {
        centerx = atoi(argv[8]);
        centery = atoi(argv[9]);
        centerz = atoi(argv[10]);
    }

    if (argc >= 14) {
        upx = atoi(argv[11]);
        upy = atoi(argv[12]);
        upz = atoi(argv[13]);
    }
        
    if (argc >= 15) {
        fovy = atoi(argv[14]);
    }

    if (!Import3DFromFile(modelname)) {
        fprintf(stderr, "model cannot be loaded!\n");
        return 0;
    }    

    /* Create an RGBA-mode context */
#if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305
    /* specify Z, stencil, accum sizes */
    ctx = OSMesaCreateContextExt( OSMESA_RGBA, 16, 0, 0, NULL );
#else
    ctx = OSMesaCreateContext( OSMESA_RGBA, NULL );
#endif
    if (!ctx) {
        printf("OSMesaCreateContext failed!\n");
        return 0;
    }

    /* Allocate the image buffer */
    buffer = malloc( Width * Height * 4 * sizeof(GLubyte) );
    if (!buffer) {
        printf("Alloc image buffer failed!\n");
        return 0;
    }

    /* Bind the buffer to the context and make it current */
    if (!OSMesaMakeCurrent( ctx, buffer, GL_UNSIGNED_BYTE, Width, Height )) {
        printf("OSMesaMakeCurrent failed!\n");
        return 0;
    }

    {
        int z, s, a;
        glGetIntegerv(GL_DEPTH_BITS, &z);
        glGetIntegerv(GL_STENCIL_BITS, &s);
        glGetIntegerv(GL_ACCUM_RED_BITS, &a);
        printf("Depth=%d Stencil=%d Accum=%d\n", z, s, a);
    }

    InitGL(Width, Height);
    render_image();

    if (pngname != NULL) {
        png::image< png::rgba_pixel > image(Width, Height);
        GLubyte * p_buffer = (GLubyte*)buffer;
        for (png::uint_32 y = 0; y < Height; ++y)
        {
            for (png::uint_32 x = 0; x < Width; ++x)
            {
                png::uint_32 r, g, b, a;
                r = *(p_buffer++);
                g = *(p_buffer++);
                b = *(p_buffer++);
                a = *(p_buffer++);
                image[Height-1-y][x] = png::rgba_pixel(r, g, b, a);
            }
        }
        image.write(pngname);
    }
    else {
        printf("Specify a filename if you want to make an image file\n");
    }

    printf("all done\n");

    /* free the image buffer */
    free( buffer );

    // *** cleanup ***
    textureIdMap.clear(); //no need to delete pointers in it manually here. (Pointers point to textureIds deleted in next step)
    textureName.clear(); //no need to delete pointers in it manually here. (Pointers point to textureIds deleted in next step)

    if (textureIds)
    {
        delete[] textureIds;
        textureIds = NULL;
    }

    /* destroy the context */
    OSMesaDestroyContext( ctx );

    return 0;
}
Exemplo n.º 15
0
int main( int argc, char *argv[] )
{
   void *buffer;
   int i;
   char *filename = NULL;


   /* Create an RGBA-mode context */
#if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305
   /* specify Z, stencil, accum sizes */
   OSMesaContext ctx = OSMesaCreateContextExt( OSMESA_RGBA, 16, 0, 0, NULL );
#else
   OSMesaContext ctx = OSMesaCreateContext( OSMESA_RGBA, NULL );
#endif
   if (!ctx) {
      printf("OSMesaCreateContext failed!\n");
      return 0;
   }

   for ( i=1; i<argc; i++ ) {
      if (argv[i][0] != '-') filename = argv[i];
   }

   /* Allocate the image buffer */
   buffer = malloc( WIDTH * HEIGHT * 4 * sizeof(GLubyte) );
   if (!buffer) {
      printf("Alloc image buffer failed!\n");
      return 0;
   }

   /* Bind the buffer to the context and make it current */
   if (!OSMesaMakeCurrent( ctx, buffer, GL_UNSIGNED_BYTE, WIDTH, HEIGHT )) {
      printf("OSMesaMakeCurrent failed!\n");
      return 0;
   }
     

   {
      int z, s, a;
      glGetIntegerv(GL_DEPTH_BITS, &z);
      glGetIntegerv(GL_STENCIL_BITS, &s);
      glGetIntegerv(GL_ACCUM_RED_BITS, &a);
      printf("Depth=%d Stencil=%d Accum=%d\n", z, s, a);
   }

  InitGL();
  RenderImage();

   if (filename != NULL) {
      write_ppm(filename, (GLubyte*)buffer, WIDTH, HEIGHT);
   }
   else {
      printf("Specify a filename (with ppm extension) if you want to make an image file\n");
   }

   printf("all done\n");

   /* free the image buffer */
   free( buffer );

   /* destroy the context */
   OSMesaDestroyContext( ctx );

   return 0;
}
Exemplo n.º 16
0
int main(int argc, char** argv) {
	/* default values */
	char * filename = "teapot.obj";
	char * diffuse  = "wood.rgba";
	char * sphere   = "nvidia.rgba";
	int c, index;

	chdir("/opt/examples");

	/* Parse some command-line arguments */
	while ((c = getopt(argc, argv, "d:e:h:s:")) != -1) {
		switch (c) {
			case 'd':
				diffuse = optarg;
				break;
			case 'e':
				sphere = optarg;
				break;
			case 's':
				/* Set scale */
				scale = atof(optarg);
				break;
			case 'h':
				cam_offset = atof(optarg);
				break;
			default:
				/* Uh, that's it for -args */
				printf("Unrecognized argument!\n");
				break;
		}
	}
	/* Get an optional filename from the last non-- parameter */
	for (index = optind; index < argc; ++index) {
		filename = argv[index];
	}

	printf("Press q to exit.\n");

	yctx = yutani_init();
	wina = yutani_window_create(yctx, 500, 500);
	yutani_window_move(yctx, wina, 100, 100);
	ctx = init_graphics_yutani_double_buffer(wina);
	draw_fill(ctx, rgb(0,0,0));
	yutani_window_update_shape(yctx, wina, YUTANI_SHAPE_THRESHOLD_HALF);

	yutani_window_advertise_icon(yctx, wina, "GL Teapot", "teapot");

	OSMesaContext gl_ctx = OSMesaCreateContext(OSMESA_BGRA, NULL);
	if (resize(ctx, gl_ctx)) {
		fprintf(stderr, "%s: Something bad happened.\n", argv[0]);
		goto finish;
	}

	/* Load up the file, set everything else up */
	init (filename, diffuse, sphere);

	/* XXX add a method to query if there are available packets in pex */
	pthread_t thread;
	pthread_create(&thread, NULL, draw_thread, NULL);

	while (!quit) {
		yutani_msg_t * m = yutani_poll(yctx);
		if (m) {
			switch (m->type) {
				case YUTANI_MSG_KEY_EVENT:
					{
						struct yutani_msg_key_event * ke = (void*)m->data;
						if (ke->event.action == KEY_ACTION_DOWN) {
							keyboard(ke->event.keycode, 0, 0);
						}
					}
					break;
				case YUTANI_MSG_WINDOW_MOUSE_EVENT:
					{
						struct yutani_msg_window_mouse_event * me = (void*)m->data;
						if (me->command == YUTANI_MOUSE_EVENT_DOWN && me->buttons & YUTANI_MOUSE_BUTTON_LEFT) {
							yutani_window_drag_start(yctx, wina);
						}
					}
					break;
				case YUTANI_MSG_SESSION_END:
					quit = 1;
					break;
				default:
					break;
			}
			free(m);
		}
	}

finish:
	OSMesaDestroyContext(gl_ctx);
	yutani_close(yctx, wina);

	return 0;
}
Exemplo n.º 17
0
Arquivo: gears.c Projeto: etel/ponyos
int main (int argc, char ** argv) {
	yutani_t * yctx;
	yutani_window_t * wina;
	gfx_context_t * ctx;
	int should_exit = 0;
	int blur = 0;
	int stopped = 0;

	int left = 30;
	int top  = 30;

	int width  = 500;
	int height = 500;

	yctx = yutani_init();
	wina = yutani_window_create(yctx, width, height);
	yutani_window_move(yctx, wina, left, top);
	ctx = init_graphics_yutani_double_buffer(wina);
	draw_fill(ctx, rgb(0,0,0));
	yutani_window_update_shape(yctx, wina, YUTANI_SHAPE_THRESHOLD_HALF);

	yutani_window_advertise_icon(yctx, wina, "Mesa Gears", "gears");

	OSMesaContext gl_ctx = OSMesaCreateContext(OSMESA_BGRA, NULL);
	if (resize(ctx, gl_ctx)) {
		fprintf(stderr, "%s: Something bad happened.\n", argv[0]);
		goto finish;
	}

	init();

	while (!should_exit) {
		yutani_msg_t * m = yutani_poll_async(yctx);
		if (m) {
			switch (m->type) {
				case YUTANI_MSG_KEY_EVENT:
					{
						struct yutani_msg_key_event * ke = (void*)m->data;
						if (ke->event.action == KEY_ACTION_DOWN) {
							switch (ke->event.keycode) {
								case 'q':
									should_exit = 1;
									free(m);
									goto finish;
								case 'b':
									blur = (1-blur);
									break;
								case 's':
									stopped = (1-stopped);
									break;
								case KEY_ARROW_LEFT:
									view_roty += 5.0;
									break;
								case KEY_ARROW_RIGHT:
									view_roty -= 5.0;
									break;
								case KEY_ARROW_UP:
									view_rotx += 5.0;
									break;
								case KEY_ARROW_DOWN:
									view_rotx -= 5.0;
									break;
								default:
									break;
							}
						}
					}
					break;
				case YUTANI_MSG_WINDOW_MOUSE_EVENT:
					{
						struct yutani_msg_window_mouse_event * me = (void*)m->data;
						if (me->command == YUTANI_MOUSE_EVENT_DOWN && me->buttons & YUTANI_MOUSE_BUTTON_LEFT) {
							yutani_window_drag_start(yctx, wina);
						}
					}
					break;
				case YUTANI_MSG_SESSION_END:
					should_exit = 1;
					break;
				case YUTANI_MSG_RESIZE_OFFER:
					{
						struct yutani_msg_window_resize * wr = (void*)m->data;
						yutani_window_resize_accept(yctx, wina, wr->width, wr->height);
						reinit_graphics_yutani(ctx, wina);
						resize(ctx, gl_ctx);
						draw();
						yutani_window_resize_done(yctx, wina);
						flip(ctx);
						yutani_flip(yctx, wina);
						yutani_window_update_shape(yctx, wina, 1);
						/* Reset statistics */
						frames = 0;
						start_time = 0;
					}
				default:
					break;
			}
			free(m);
		}
		fps();
		if (!stopped) {
			angle += 0.2;
		}
		draw();
		if (blur) {
			blur_context_box(ctx, 20);
		}
		flip(ctx);
		yutani_flip(yctx, wina);
		syscall_yield();
	}

finish:
	OSMesaDestroyContext(gl_ctx);
	yutani_close(yctx, wina);

	return 0;
}