示例#1
0
Color
Surface::get_pixel(int x, int y) const
{
    Uint8 *p = static_cast<Uint8 *>(get_surface()->pixels) + y * get_surface()->pitch + x * get_surface()->format->BytesPerPixel;
    Uint32 pixel;

    switch(get_surface()->format->BytesPerPixel)
    {
    case 1:
        pixel = *p;
    case 2: /* This will cause some problems ... */
        pixel = *reinterpret_cast<Uint16*>(p);
    case 3:
        if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
            pixel = p[0] << 16 | p[1] << 8 | p[2];
        else
            pixel = p[0] | p[1] << 8 | p[2] << 16;
    case 4:
        pixel = *reinterpret_cast<Uint32*>(p);
    default:
        pixel = 0;       /* shouldn't happen, but avoids warnings */
    }

    Color color;
    SDL_GetRGBA(pixel, get_surface()->format, &color.r, &color.g, &color.b, &color.a);
    return color;
}
示例#2
0
int
Surface::get_height() const
{
    if (get_surface())
        return get_surface()->h;
    else
        return 0;
}
示例#3
0
int
Surface::get_pitch() const
{
    if (get_surface())
        return get_surface()->pitch;
    else
        return 0;
}
示例#4
0
int
Surface::get_width()  const
{
    if (get_surface())
        return get_surface()->w;
    else
        return 0;
}
示例#5
0
void draw_surface_ext(int id, gs_scalar x, gs_scalar y, gs_scalar xscale, gs_scalar yscale, double rot, int color, gs_scalar alpha)
{
  get_surface(surf,id);
  texture_use(surf->tex);

  glPushAttrib(GL_CURRENT_BIT);
    glColor4ub(__GETR(color),__GETG(color),__GETB(color),char(alpha*255));

    const gs_scalar w=surf->width*xscale, h=surf->height*yscale;
    rot *= M_PI/180;

    gs_scalar ulcx = x + xscale * cos(M_PI+rot) + yscale * cos(M_PI/2+rot),
          ulcy = y - yscale * sin(M_PI+rot) - yscale * sin(M_PI/2+rot);

    glBegin(GL_QUADS);
      glTexCoord2f(0,0);
        glVertex2f(ulcx,ulcy);
      glTexCoord2f(1,0);
        glVertex2f(ulcx + w*cos(rot), ulcy - w*sin(rot));
      glTexCoord2f(1,1);
        ulcx += h * cos(3*M_PI/2 + rot);
        ulcy -= h * sin(3*M_PI/2 + rot);
        glVertex2f(ulcx + w*cos(rot), ulcy - w*sin(rot));
      glTexCoord2f(0,1);
        glVertex2f(ulcx,ulcy);
    glEnd();
  glPopAttrib();
}
示例#6
0
void draw_surface_tiled_ext(int id, gs_scalar x, gs_scalar y, gs_scalar xscale, gs_scalar yscale, int color, gs_scalar alpha)
{
  get_surface(surf,id);
  texture_use(surf->tex);

  glPushAttrib(GL_CURRENT_BIT);
    glColor4ub(__GETR(color),__GETG(color),__GETB(color),char(alpha*255));
    const gs_scalar w=surf->width*xscale, h=surf->height*yscale;
    const int hortil= int (ceil(room_width/(surf->width))),
        vertil= int (ceil(room_height/(surf->height)));
    x=w-fmod(x,w);
    y=h-fmod(y,h);
    glBegin(GL_QUADS);
    for (int i=0; i<hortil; i++)
    {
      for (int c=0; c<vertil; c++)
      {
        glTexCoord2f(0,0);
          glVertex2f(i*w-x,c*h-y);
        glTexCoord2f(1,0);
          glVertex2f((i+1)*w-x,c*h-y);
        glTexCoord2f(1,1);
          glVertex2f((i+1)*w-x,(c+1)*h-y);
        glTexCoord2f(0,1);
          glVertex2f(i*w-x,(c+1)*h-y);
      }
    }
    glEnd();
  glPopAttrib();
}
示例#7
0
void draw_surface_general(int id, gs_scalar left, gs_scalar top, gs_scalar width, gs_scalar height, gs_scalar x, gs_scalar y, gs_scalar xscale, gs_scalar yscale, double rot, int c1, int c2, int c3, int c4, gs_scalar a1, gs_scalar a2, gs_scalar a3, gs_scalar a4)
{
  get_surface(surf,id);
  texture_use(surf->tex);

  glPushAttrib(GL_CURRENT_BIT);
    const gs_scalar tbw = surf->width, tbh = surf->height,
      w = width*xscale, h = height*yscale;

    rot *= M_PI/180;

    gs_scalar ulcx = x + xscale * cos(M_PI+rot) + yscale * cos(M_PI/2+rot),
          ulcy = y - yscale * sin(M_PI+rot) - yscale * sin(M_PI/2+rot);

    glBegin(GL_QUADS);
      glColor4ub(__GETR(c1),__GETG(c1),__GETB(c1),char(a1*255));
      glTexCoord2f(left/tbw,top/tbh);
        glVertex2f(ulcx,ulcy);

      glColor4ub(__GETR(c2),__GETG(c2),__GETB(c2),char(a2*255));
      glTexCoord2f((left+width)/tbw,top/tbh);
        glVertex2f((ulcx + w*cos(rot)), (ulcy - w*sin(rot)));

      ulcx += h * cos(3*M_PI/2 + rot);
      ulcy -= h * sin(3*M_PI/2 + rot);
      glColor4ub(__GETR(c3),__GETG(c3),__GETB(c3),char(a3*255));
      glTexCoord2f((left+width)/tbw,(top+height)/tbh);
        glVertex2f((ulcx + w*cos(rot)), (ulcy - w*sin(rot)));

      glColor4ub(__GETR(c4),__GETG(c4),__GETB(c4),char(a4*255));
      glTexCoord2f(left/tbw,(top+height)/tbh);
        glVertex2f(ulcx,ulcy);
    glEnd();
  glPopAttrib();
}
static void
champlain_point_get_property (GObject *object,
    guint prop_id,
    GValue *value,
    GParamSpec *pspec)
{
  ChamplainPointPrivate *priv = CHAMPLAIN_POINT (object)->priv;

  switch (prop_id)
    {
    case PROP_COLOR:
      clutter_value_set_color (value, priv->color);
      break;

    case PROP_SIZE:
      g_value_set_double (value, priv->size);
      break;

    case PROP_SURFACE:
      g_value_set_boxed (value, get_surface (CHAMPLAIN_EXPORTABLE (object)));
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}
示例#9
0
void draw_surface_tiled(int id, gs_scalar x, gs_scalar y)
{
  get_surface(surf,id);
  texture_use(surf->tex);

  glPushAttrib(GL_CURRENT_BIT);
    glColor4f(1,1,1,1);
    x=surf->width-fmod(x,surf->width);
    y=surf->height-fmod(y,surf->height);
    const int hortil= int (ceil(room_width/(surf->width))),
              vertil= int (ceil(room_height/(surf->height)));

    glBegin(GL_QUADS);
      for (int i=0; i<hortil; i++)
      {
        for (int c=0; c<vertil; c++)
        {
          glTexCoord2f(0,0);
            glVertex2f(i*surf->width-x,c*surf->height-y);
          glTexCoord2f(1,0);
            glVertex2f((i+1)*surf->width-x,c*surf->height-y);
          glTexCoord2f(1,1);
            glVertex2f((i+1)*surf->width-x,(c+1)*surf->height-y);
          glTexCoord2f(0,1);
            glVertex2f(i*surf->width-x,(c+1)*surf->height-y);
        }
      }
    glEnd();
  glPopAttrib();
}
示例#10
0
void surface_free(int id)
{
  get_surface(surf,id);
  surf->width = surf->height = surf->tex = surf->fbo = 0;
  delete surf;
  enigma::surface_array[id] = NULL;
}
示例#11
0
文件: aa_screen.cpp 项目: K0F/FreeJ
void AaScreen::blit(Layer *src) {
    int16_t c;
    Blit *b;

    if(src->screen != this) {
        error("%s: blit called on a layer not belonging to screen",
              __PRETTY_FUNCTION__);
        return;
    }

    if(src->need_crop)
        src->blitter->crop(src, this);

    b = src->current_blit;

    pscr = (uint32_t*) get_surface() + b->scr_offset;
    play = (uint32_t*) src->buffer   + b->lay_offset;

    // iterates the blit on each horizontal line
    for(c = b->lay_height; c > 0; c--) {

        (*b->fun)
            ((void*)play, (void*)pscr,
            b->lay_bytepitch, // * src->geo.bpp>>3,
            &b->parameters);

        // strides down to the next line
        pscr += b->scr_stride + b->lay_pitch;
        play += b->lay_stride + b->lay_pitch;

    }

}
示例#12
0
Size
Surface::get_size()  const
{
    if (get_surface())
        return Size(impl->surface->w, impl->surface->h);
    else
        return Size();
}
示例#13
0
geom::Size mtc::SessionManagementContext::get_window_size(std::string const& window_name)
{
    auto window = open_windows[window_name];
    auto session = std::get<0>(window);
    auto surface_id = std::get<1>(window);

    return session->get_surface(surface_id)->size();
}
示例#14
0
文件: aa_screen.cpp 项目: K0F/FreeJ
void *AaScreen::coords(int x, int y) {
//   func("method coords(%i,%i) invoked", x, y);
// if you are trying to get a cropped part of the layer
// use the .pixelsize geometric property for a pre-calculated stride
// that is: number of bytes for one full line
    return
        (x + geo.pixelsize * y +
         (uint32_t*)get_surface());
}
示例#15
0
void surface_set_target(int id)
{
  draw_batch_flush(batch_flush_deferred);

  get_surface(surface,id);
  d3ddev->SetRenderTarget(0, surface.surf);

  d3d_set_projection_ortho(0, 0, surface.width, surface.height, 0);
}
EGLBoolean egl_display_t::makeCurrent(egl_context_t* c, egl_context_t* cur_c,
        EGLSurface draw, EGLSurface read, EGLContext ctx,
        EGLSurface impl_draw, EGLSurface impl_read, EGLContext impl_ctx)
{
    EGLBoolean result;

    // by construction, these are either 0 or valid (possibly terminated)
    // it should be impossible for these to be invalid
    ContextRef _cur_c(cur_c);
    SurfaceRef _cur_r(cur_c ? get_surface(cur_c->read) : NULL);
    SurfaceRef _cur_d(cur_c ? get_surface(cur_c->draw) : NULL);

    { // scope for the lock
        Mutex::Autolock _l(lock);
        if (c) {
            result = c->cnx->egl.eglMakeCurrent(
                    disp.dpy, impl_draw, impl_read, impl_ctx);
            if (result == EGL_TRUE) {
                c->onMakeCurrent(draw, read);
                if (!cur_c) {
                    mHibernation.incWakeCount(HibernationMachine::STRONG);
                }
            }
        } else {
            result = cur_c->cnx->egl.eglMakeCurrent(
                    disp.dpy, impl_draw, impl_read, impl_ctx);
            if (result == EGL_TRUE) {
                cur_c->onLooseCurrent();
                mHibernation.decWakeCount(HibernationMachine::STRONG);
            }
        }
    }

    if (result == EGL_TRUE) {
        // This cannot be called with the lock held because it might end-up
        // calling back into EGL (in particular when a surface is destroyed
        // it calls ANativeWindow::disconnect
        _cur_c.release();
        _cur_r.release();
        _cur_d.release();
    }

    return result;
}
示例#17
0
void surface_set_target(int id)
{
  get_surface(surf,id);
  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, surf->fbo); //bind it
  glPushMatrix(); //So you can pop it in the reset
  glPushAttrib(GL_VIEWPORT_BIT); //same
  glViewport(0,0,surf->width,surf->height);
  glLoadIdentity();
  glOrtho(-1, surf->width, -1, surf->height, -1, 1);
}
示例#18
0
void surface_free(int id)
{
  get_surface(surf,id);
  if (enigma::bound_framebuffer == surf->fbo) glBindFramebuffer(GL_DRAW_FRAMEBUFFER, enigma::bound_framebuffer=0);
  enigma::graphics_delete_texture(surf->tex);
  glDeleteFramebuffers(1, &surf->fbo);
  surf->width = surf->height = surf->tex = surf->fbo = 0;
  delete surf;
  enigma::surface_array[id] = NULL;
}
示例#19
0
void surface_copy(int destination, float x, float y, int source)
{
    get_surface(ssurf,source);
    get_surface(dsurf,destination);
    unsigned char *surfbuf=new unsigned char[dsurf->width*dsurf->height*4];
    glBindFramebuffer(GL_READ_FRAMEBUFFER, ssurf->fbo);
	glReadPixels(0,0,dsurf->width,dsurf->height,GL_RGBA,GL_UNSIGNED_BYTE,surfbuf);
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, dsurf->fbo);
    glPushMatrix();
    glPushAttrib(GL_VIEWPORT_BIT);
    screen_set_viewport(0, 0, dsurf->width, dsurf->height);
    d3d_set_projection_ortho(0, 0, dsurf->width, dsurf->height, 0);
	glRasterPos2d(x, y);
	glDrawPixels(dsurf->width,dsurf->height,GL_RGBA,GL_UNSIGNED_BYTE,surfbuf);
	glBindFramebuffer(GL_READ_FRAMEBUFFER, enigma::bound_framebuffer);
    glPopAttrib();
    glPopMatrix();
	glRasterPos2d(0, 0);
	delete[] surfbuf;
}
void surface_set_target(int id)
{
  get_surface(surface,id);
  d3dmgr->device->GetRenderTarget(0, &pBackBuffer);
  d3dmgr->device->SetRenderTarget(0, surface->surf);

  D3DXMATRIX matProjection;
  D3DXMatrixPerspectiveFovLH(&matProjection,D3DX_PI / 4.0f,1,1,100);
  //set projection matrix
  d3dmgr->SetTransform(D3DTS_PROJECTION,&matProjection);
}
示例#21
0
void
Surface::blit(const Surface& src, int x, int y)
{
    if (!get_surface())
    {
        std::cout << "Surface: Trying to blit to empty surface" << std::endl;
    }
    else if (!src.get_surface())
    {
        std::cout << "Surface: Trying to blit with an empty surface" << std::endl;
    }
    else
    {
        SDL_Rect dstrect;

        dstrect.x = static_cast<Sint16>(x);
        dstrect.y = static_cast<Sint16>(y);

        SDL_BlitSurface(src.get_surface(), NULL, get_surface(), &dstrect);
    }
}
void egl_display_t::loseCurrentImpl(egl_context_t * cur_c)
{
    // by construction, these are either 0 or valid (possibly terminated)
    // it should be impossible for these to be invalid
    ContextRef _cur_c(cur_c);
    SurfaceRef _cur_r(cur_c ? get_surface(cur_c->read) : NULL);
    SurfaceRef _cur_d(cur_c ? get_surface(cur_c->draw) : NULL);

    { // scope for the lock
        Mutex::Autolock _l(lock);
        cur_c->onLooseCurrent();

    }

    // This cannot be called with the lock held because it might end-up
    // calling back into EGL (in particular when a surface is destroyed
    // it calls ANativeWindow::disconnect
    _cur_c.release();
    _cur_r.release();
    _cur_d.release();
}
示例#23
0
void draw_60()
{
    SDL_Surface * image=get_surface("spacef");
    int w=image->w;
    int h=image->h;
    for(int i=0; i<(480/h)+3; i++)
    {
        for(int j=0; j<(640/w)+3; j++)
        {
            draw_tile(image, j*w-w+15, i*h-h+21, 1.6);
        }
    }
}
示例#24
0
void draw_100()
{
    SDL_Surface * image=get_surface("spaceb");
    int w=image->w;
    int h=image->h;
    for(int i=0; i<(480/h)+3; i++)
    {
        for(int j=0; j<(640/w)+3; j++)
        {
            draw_tile(image, j*w-w, i*h-h, .4);
        }
    }
}
示例#25
0
void surface_set_target(int id)
{
  get_surface(surf,id);
  texture_reset();
  //This fixes several consecutive surface_set_target() calls without surface_reset_target.
  if (enigma::bound_framebuffer != 0) glPopAttrib(); glPopMatrix();
  enigma::bound_framebuffer = surf->fbo;
  glBindFramebuffer(GL_DRAW_FRAMEBUFFER, surf->fbo); //bind it
  glPushMatrix(); //So you can pop it in the reset
  glPushAttrib(GL_VIEWPORT_BIT); //same
  screen_set_viewport(0, 0, surf->width, surf->height);
  d3d_set_projection_ortho(0, 0, surf->width, surf->height, 0);
}
示例#26
0
void sprite_add_from_surface(int ind, int id, int x, int y, int w, int h, bool removeback, bool smooth)
{
    get_surface(surf,id);
    int full_width=nlpo2dc(w)+1, full_height=nlpo2dc(h)+1;

    unsigned sz=full_width*full_height;
    unsigned char *surfbuf=new unsigned char[sz*4];
    glBindFramebuffer(GL_READ_FRAMEBUFFER, surf->fbo);
    glReadPixels(x,y,w,h,GL_RGBA,GL_UNSIGNED_BYTE,surfbuf);
    glBindFramebuffer(GL_READ_FRAMEBUFFER, enigma::bound_framebuffer);
    enigma::sprite_add_subimage(ind, w, h, surfbuf, surfbuf, enigma::ct_precise); //TODO: Support toggling of precise.
    delete[] surfbuf;
}
示例#27
0
void draw_80()
{
    SDL_Surface * image=get_surface("spacem");
    int w=image->w;
    int h=image->h;
    for(int i=0; i<(480/h)+3; i++)
    {
        for(int j=0; j<(640/w)+3; j++)
        {
            draw_tile(image, j*w-w-4, i*h-h+34, .8);
        }
    }
}
示例#28
0
void draw_surface_tiled_area_ext(int id, gs_scalar x, gs_scalar y, gs_scalar x1, gs_scalar y1, gs_scalar x2, gs_scalar y2, gs_scalar xscale, gs_scalar yscale, int color, gs_scalar alpha)
{
  get_surface(surf,id);
  texture_use(surf->tex);

  glPushAttrib(GL_CURRENT_BIT);
    glColor4ub(__GETR(color),__GETG(color),__GETB(color),char(alpha*255));

    gs_scalar sw,sh,i,j,jj,left,top,width,height,X,Y;
    sw = surf->width*xscale;
    sh = surf->height*yscale;

    i = x1-(fmod(x1,sw) - fmod(x,sw)) - sw*(fmod(x1,sw)<fmod(x,sw));
    j = y1-(fmod(y1,sh) - fmod(y,sh)) - sh*(fmod(y1,sh)<fmod(y,sh));
    jj = j;

    glBegin(GL_QUADS);
    for(; i<=x2; i+=sw)
    {
      for(; j<=y2; j+=sh)
      {
        if(i <= x1) left = x1-i;
        else left = 0;
        X = i+left;

        if(j <= y1) top = y1-j;
        else top = 0;
        Y = j+top;

        if(x2 <= i+sw) width = ((sw)-(i+sw-x2)+1)-left;
        else width = sw-left;

        if(y2 <= j+sh) height = ((sh)-(j+sh-y2)+1)-top;
        else height = sh-top;

        glTexCoord2f(left/sw,top/sh);
          glVertex2f(X,Y);
        glTexCoord2f((left+width)/sw,top/sh);
          glVertex2f(X+width,Y);
        glTexCoord2f((left+width)/sw,(top+height)/sh);
          glVertex2f(X+width,Y+height);
        glTexCoord2f(left/sw,(top+height)/sh);
          glVertex2f(X,Y+height);
      }
      j = jj;
    }
    glEnd();
  glPopAttrib();
}
示例#29
0
void draw_surface_tiled_area(int id,double x,double y,double x1,double y1,double x2,double y2)
{
  get_surface(surf,id);
  texture_use(surf->tex);

  glPushAttrib(GL_CURRENT_BIT);
    glColor4f(1,1,1,1);

    float sw,sh,i,j,jj,left,top,width,height,X,Y;
    sw = surf->width;
    sh = surf->height;

    i = x1-(fmod(x1,sw) - fmod(x,sw)) - sw*(fmod(x1,sw)<fmod(x,sw));
    j = y1-(fmod(y1,sh) - fmod(y,sh)) - sh*(fmod(y1,sh)<fmod(y,sh));
    jj = j;

    glBegin(GL_QUADS);
    for(i=i; i<=x2; i+=sw)
    {
      for(j=j; j<=y2; j+=sh)
      {
        if(i <= x1) left = x1-i;
        else left = 0;
        X = i+left;

        if(j <= y1) top = y1-j;
        else top = 0;
        Y = j+top;

        if(x2 <= i+sw) width = ((sw)-(i+sw-x2)+1)-left;
        else width = sw-left;

        if(y2 <= j+sh) height = ((sh)-(j+sh-y2)+1)-top;
        else height = sh-top;

        glTexCoord2f(left/sw,top/sh);
          glVertex2f(X,Y);
        glTexCoord2f((left+width)/sw,top/sh);
          glVertex2f(X+width,Y);
        glTexCoord2f((left+width)/sw,(top+height)/sh);
          glVertex2f(X+width,Y+height);
        glTexCoord2f(left/sw,(top+height)/sh);
          glVertex2f(X,Y+height);
      }
      j = jj;
    }
    glEnd();
  glPopAttrib();
}
/**
 * clutter_cairo_texture_clear:
 * @self: a #ClutterCairoTexture
 *
 * Clears @self's internal drawing surface, so that the next upload
 * will replace the previous contents of the #ClutterCairoTexture
 * rather than adding to it.
 *
 * Since: 1.0
 */
void
clutter_cairo_texture_clear (ClutterCairoTexture *self)
{
  cairo_surface_t *surface;
  cairo_t *cr;

  g_return_if_fail (CLUTTER_IS_CAIRO_TEXTURE (self));

  surface = get_surface (self);

  cr = cairo_create (surface);
  cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
  cairo_paint (cr);
  cairo_destroy (cr);
}