Exemple #1
0
int surface_save(int id, string filename)
{
  draw_batch_flush(batch_flush_deferred);

  get_surfacev(surface,id,-1);
  string ext = enigma::image_get_format(filename);

  LPDIRECT3DSURFACE9 pDestBuffer;
  D3DSURFACE_DESC desc;
  surface.surf->GetDesc(&desc);

  d3ddev->CreateOffscreenPlainSurface( desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &pDestBuffer, NULL );
  d3ddev->GetRenderTargetData(surface.surf, pDestBuffer);

  D3DLOCKED_RECT rect;

  pDestBuffer->LockRect(&rect, NULL, D3DLOCK_READONLY);
  unsigned char* bitmap = static_cast<unsigned char*>(rect.pBits);
  pDestBuffer->UnlockRect();

  int ret = enigma::image_save(filename, bitmap, desc.Width, desc.Height, desc.Width, desc.Height, false);

  pDestBuffer->Release();

  return ret;
}
Exemple #2
0
int surface_getpixel_alpha(int id, int x, int y)
{
    get_surfacev(surf,id,-1);
    unsigned char *pixelbuf=new unsigned char[1];
    glBindFramebuffer(GL_READ_FRAMEBUFFER, surf->fbo);
	glReadPixels(x,y,1,1,GL_ALPHA,GL_UNSIGNED_BYTE,pixelbuf);
	glBindFramebuffer(GL_READ_FRAMEBUFFER, enigma::bound_framebuffer);
    return pixelbuf[0];
}
Exemple #3
0
int surface_getpixel_ext(int id, int x, int y)
{
    get_surfacev(surf,id,-1);
    unsigned char *pixelbuf=new unsigned char[3];
    glBindFramebuffer(GL_READ_FRAMEBUFFER, surf->fbo);
	glReadPixels(x,y,1,1,GL_RGBA,GL_UNSIGNED_BYTE,pixelbuf);
	glBindFramebuffer(GL_READ_FRAMEBUFFER, enigma::bound_framebuffer);
    return pixelbuf[0] + (pixelbuf[1] << 8) + (pixelbuf[2] << 16) + (pixelbuf[3] << 24);
}
Exemple #4
0
int surface_getpixel_alpha(int id, int x, int y)
{
    get_surfacev(surf,id,-1);
    unsigned char *pixelbuf=new unsigned char[1];
    int prevFbo;
	glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &prevFbo);
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, surf->fbo);
	glReadPixels(x,y,1,1,GL_ALPHA,GL_UNSIGNED_BYTE,pixelbuf);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, prevFbo);
    return pixelbuf[0];
}
Exemple #5
0
int sprite_create_from_surface(int id, int x, int y, int w, int h, bool removeback, bool smooth, bool preload, int xorig, int yorig)
{
    get_surfacev(surf,id,-1);
    int full_width=nlpo2dc(w)+1, full_height=nlpo2dc(h)+1;
    enigma::spritestructarray_reallocate();
    int sprid=enigma::sprite_idmax;
    enigma::sprite_new_empty(sprid, 1, w, h, xorig, yorig, 0, h, 0, w, preload, smooth);

    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_set_subimage(sprid, 0, w, h, surfbuf, surfbuf, enigma::ct_precise); //TODO: Support toggling of precise.
    delete[] surfbuf;
    return sprid;
}
Exemple #6
0
int background_create_from_surface(int id, int x, int y, int w, int h, bool removeback, bool smooth, bool preload)
{
    get_surfacev(surf,id,-1);
    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::backgroundstructarray_reallocate();
    int bckid=enigma::background_idmax;
	enigma::background_new(bckid, w, h, surfbuf, removeback, smooth, preload, false, 0, 0, 0, 0, 0, 0);
    delete[] surfbuf;
	enigma::background_idmax++;
    return bckid;
}
Exemple #7
0
int surface_save_part(int id, string filename, unsigned x, unsigned y, unsigned w, unsigned h)
{
    get_surfacev(surf,id,-1);
	unsigned int sz=w*h;

    string ext = enigma::image_get_format(filename);

    unsigned char *rgbdata = new unsigned char[sz*4];

	glBindFramebuffer(GL_READ_FRAMEBUFFER, surf->fbo);
	glPixelStorei(GL_PACK_ALIGNMENT, 1);
	glReadPixels(x,y,w,h,GL_RGBA,GL_UNSIGNED_BYTE,rgbdata);
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, enigma::bound_framebuffer);

	int ret = enigma::image_save(filename, rgbdata, w, h, w, h, false);

	delete[] rgbdata;
	return ret;
}
Exemple #8
0
int surface_getpixel_alpha(int id, int x, int y)
{
  get_surfacev(surface,id,-1);
  if (x < 0) x = 0;
  if (y < 0) y = 0;
  if (x > surface.width || y > surface.height) return 0;
  draw_batch_flush(batch_flush_deferred);

  LPDIRECT3DSURFACE9 pBuffer = surface.surf, pRamBuffer;
  enigma::surface_copy_to_ram(&pBuffer, &pRamBuffer);

  D3DLOCKED_RECT rect;

  pRamBuffer->LockRect(&rect, NULL, D3DLOCK_READONLY);
  unsigned char* bitmap = static_cast<unsigned char*>(rect.pBits);
  unsigned offset = y * rect.Pitch + x * 4;
  int ret = bitmap[offset + 3];
  pRamBuffer->UnlockRect();

  pRamBuffer->Release();

  return ret;
}
int surface_getpixel_alpha(int id, int x, int y)
{
  get_surfacev(surface,id,-1);
  if (x < 0) x = 0;
  if (y < 0) y = 0;
  if (x > surface->width || y > surface->height) return 0;

  d3dmgr->EndShapesBatching();
  LPDIRECT3DSURFACE9 pBuffer = surface->surf;
  d3dmgr->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer);
  D3DSURFACE_DESC desc;
  pBackBuffer->GetDesc(&desc);

  D3DLOCKED_RECT rect;

  pBuffer->LockRect(&rect, NULL, D3DLOCK_READONLY);
  unsigned char* bitmap = static_cast<unsigned char*>(rect.pBits);
  unsigned offset = y * rect.Pitch + x * 4;
  int ret = bitmap[offset];
  pBuffer->UnlockRect();
  delete[] bitmap;

  return ret;
}
Exemple #10
0
int surface_get_height(int id)
{
    get_surfacev(surf,id,-1);
    return (surf->height);
}
Exemple #11
0
int surface_get_width(int id)
{
    get_surfacev(surf,id,-1);
    return (surf->width);
}
Exemple #12
0
int surface_get_texture(int id)
{
    get_surfacev(surf,id,-1);
    return (surf->tex);
}