Exemplo n.º 1
0
void CALL HGE_Impl::Gfx_RenderQuad(const hgeQuad *quad)
{

    glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
    glBindTexture(GL_TEXTURE_2D, quad->tex);

    _SetBlendMode(quad->blend);


    //TODO: insert code here
    GLfloat verteces[12] = {
        quad->v[3].x, quad->v[3].y, quad->v[3].z,
        quad->v[2].x, quad->v[2].y, quad->v[2].z,
        quad->v[1].x, quad->v[1].y, quad->v[1].z,
        quad->v[0].x, quad->v[0].y, quad->v[0].z,
    };

    GLfloat texCoords[8] = {
        quad->v[3].tx, quad->v[3].ty,
        quad->v[2].tx, quad->v[2].ty,
        quad->v[1].tx, quad->v[1].ty,
        quad->v[0].tx, quad->v[0].ty,
    };
    GLubyte colors[16] = {
        (GLubyte)GETR(quad->v[3].col), (GLubyte)GETG(quad->v[3].col), (GLubyte)GETB(quad->v[3].col), (GLubyte)GETA(quad->v[3].col),
        (GLubyte)GETR(quad->v[2].col), (GLubyte)GETG(quad->v[2].col), (GLubyte)GETB(quad->v[2].col), (GLubyte)GETA(quad->v[2].col),
        (GLubyte)GETR(quad->v[1].col), (GLubyte)GETG(quad->v[1].col), (GLubyte)GETB(quad->v[1].col), (GLubyte)GETA(quad->v[1].col),
        (GLubyte)GETR(quad->v[0].col), (GLubyte)GETG(quad->v[0].col), (GLubyte)GETB(quad->v[0].col), (GLubyte)GETA(quad->v[0].col),

    };


    glVertexPointer(3, GL_FLOAT, 0, verteces);
    glEnableClientState(GL_VERTEX_ARRAY);

    glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);


    glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);
    glEnableClientState(GL_COLOR_ARRAY);

    glDrawArrays(GL_QUADS, 0, 4);

    glDisable(GL_TEXTURE_2D); // Enable Texture Mapping
    glDisable(GL_BLEND); // Enable Texture Mapping
    glBindTexture(GL_TEXTURE_2D, 0);


}
Exemplo n.º 2
0
void d3d_vertex_texture_color(double x, double y, double z, double tx, double ty, int color, double alpha)
{
    glColor4f(GETR(color), GETG(color), GETB(color), alpha);
    glTexCoord2f(tx,ty);
    glVertex3d(x,y,z);
    glColor4ubv(enigma::currentcolor);
}
Exemplo n.º 3
0
void d3d_vertex_texture_color(gs_scalar x, gs_scalar y, gs_scalar z, gs_scalar tx, gs_scalar ty, int color, double alpha)
{
    glColor4f(GETR(color), GETG(color), GETB(color), alpha);
    glTexCoord2f(tx,ty);
    glVertex3d(x,y,z);
    glColor4ubv(enigma::currentcolor);
}
Exemplo n.º 4
0
void CALL HGE_Impl::Gfx_Clear(DWORD color)
{
    //TODO: set given color
    glClearColor((float)GETR(color)/0xff, (float)GETG(color)/0xff, (float)GETB(color)/0xff, (float)GETA(color)/0xff);

    glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT);
}
Exemplo n.º 5
0
    void HGEImage::convertToDisplayFormat()
    {
        DWORD *pLockPtr = mHGE->Texture_Lock(mTexture);

        if (pLockPtr == NULL)
        {
            throw GCN_EXCEPTION("Locking of the texture failed. HGE only support locking of 32bit textures.");
        }

        int i;
        int end = mHGE->Texture_GetWidth(mTexture, true) *
            mHGE->Texture_GetHeight(mTexture, true);

        for (i = 0; i < end; i++)
        {
            DWORD color = pLockPtr[i];
            if (GETR(color) == 0xFF
                && GETG(color) == 0x00
                && GETB(color) == 0xFF)
            {
                pLockPtr[i] = ARGB(0x00, 0x00, 0x00, 0x00);
            }
        }

        mHGE->Texture_Unlock(mTexture);

        mHGESprite = new hgeSprite(mTexture,  
                                   0, 
                                   0, 
                                   mHGE->Texture_GetWidth(mTexture, true),
                                   mHGE->Texture_GetHeight(mTexture, true));
    }
Exemplo n.º 6
0
void d3d_vertex_normal_color(gs_scalar x, gs_scalar y, gs_scalar z, gs_scalar nx, gs_scalar ny, gs_scalar nz, int color, double alpha)
{
    glColor4f(GETR(color), GETG(color), GETB(color), alpha);
    glNormal3f(nx, ny, nz);
    glVertex3d(x,y,z);
    glColor4ubv(enigma::currentcolor);
}
Exemplo n.º 7
0
void d3d_vertex_normal_color(double x, double y, double z, double nx, double ny, double nz, int color, double alpha)
{
    glColor4f(GETR(color), GETG(color), GETB(color), alpha);
    glNormal3f(nx, ny, nz);
    glVertex3d(x,y,z);
    glColor4ubv(enigma::currentcolor);
}
Exemplo n.º 8
0
void ncGraphics::clear(unsigned int color) {
    glClearColor(
        GETR(color) / 255.f,
        GETG(color) / 255.f,
        GETB(color) / 255.f,
        GETA(color) / 255.f
    );
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
}
Exemplo n.º 9
0
void HGE_CALL HGE_Impl::Gfx_Clear(hgeU32 color)
{
	float c[4] = {
		(float)GETA(color) / 256,
		(float)GETR(color) / 256,
		(float)GETG(color) / 256,
		(float)GETB(color) / 256 };
	m_pD3DDeviceContext->ClearRenderTargetView(pRTView, c);
	//m_pD3DDeviceContext->ClearDepthStencilView(pDSView, D3D11_CLEAR_DEPTH, 1.0f, 0);
}
Exemplo n.º 10
0
/* jpeg_save_img:
 * Write an image out into a JPEG file. */
int jpeg_save_img(const img I, FILE *fp) {
    struct jpeg_compress_struct cinfo;
    struct my_error_mgr jerr;
    JSAMPROW *buffer;

    cinfo.err = jpeg_std_error(&jerr.pub);
    jerr.pub.error_exit = my_error_exit;
    if (setjmp(jerr.jb)) {
        /* Oops, something went wrong. */
        I->err = IE_SYSERROR;
        jpeg_destroy_compress(&cinfo);
        return 0;
    }

    jpeg_create_compress(&cinfo);

    /* Compressor will write to fp. */
    jpeg_stdio_dest(&cinfo, fp);

    /* Image parameters. */
    cinfo.image_width = I->width;
    cinfo.image_height = I->height;
    cinfo.input_components = 3;
    cinfo.in_color_space = JCS_RGB;

    /* Default parameters. */
    jpeg_set_defaults(&cinfo);

    /* XXX compression quality? */

    jpeg_start_compress(&cinfo, TRUE);

    buffer = cinfo.mem->alloc_sarray((j_common_ptr)&cinfo, JPOOL_IMAGE, I->width * 3, 1);

    while (cinfo.next_scanline < cinfo.image_height) {
        pel *p, *end;
        unsigned char *q;
        /* Copy image data into correct format. */
        for (p = I->data[cinfo.next_scanline], end = p + I->width, q = (unsigned char*)buffer[0]; p < end; ++p) {
            *q++ = (unsigned char)GETR(*p);
            *q++ = (unsigned char)GETG(*p);
            *q++ = (unsigned char)GETB(*p);
        }

        /* Write scanline. */
        jpeg_write_scanlines(&cinfo, buffer, 1);
    }

    jpeg_finish_compress(&cinfo);
    jpeg_destroy_compress(&cinfo);

    return 1;
}
Exemplo n.º 11
0
bool CApp::init() {
	if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
		return false;

	_window = SDL_CreateWindow(TITLE, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_W, SCREEN_H, 0);
	_renderer = SDL_CreateRenderer(_window, -1, SDL_RENDERER_PRESENTVSYNC);
	SDL_SetRenderDrawColor(_renderer, GETR(COLOR_BG), GETG(COLOR_BG), GETB(COLOR_BG), SDL_ALPHA_OPAQUE);
	SDL_RenderClear(_renderer);

	_game.set_renderer(_renderer);
	_currentState = &_game;

	return true;
}
Exemplo n.º 12
0
    Color HGEImage::getPixel(int x, int y)
    {
        DWORD *pLockPtr = mHGE->Texture_Lock(mTexture);

        if (pLockPtr == NULL)
        {
            throw GCN_EXCEPTION("Locking of the texture failed. HGE only support locking of 32bit textures.");
        }

        DWORD color = pLockPtr[x + y * mHGE->Texture_GetWidth(mTexture, true)];

        mHGE->Texture_Unlock(mTexture);

        return Color(GETR(color),
                     GETG(color), 
                     GETB(color), 
                     GETA(color ));
    }
Exemplo n.º 13
0
/*
    Get the color of a pen.
*/
static void GDI_get_pen(int pen, unsigned char* pRed, unsigned char* pGreen, unsigned char* pBlue)
{
    if (This.m_nDepth != 8 && This.m_bModifiablePalette == FALSE)
    {
        *pRed   = GETR(pen);
        *pGreen = GETG(pen);
        *pBlue  = GETB(pen);
    }
    else
    {
        assert(0 <= pen && pen < This.m_nTotalColors);

        if (This.m_nTotalColors <= pen)
            pen = 0;

        *pRed   = This.m_PalEntries[pen].peRed;
        *pGreen = This.m_PalEntries[pen].peGreen;
        *pBlue  = This.m_PalEntries[pen].peBlue;
    }
}
Exemplo n.º 14
0
/*****
* Name: 		ReadColormap
* Return Type: 	Boolean
* Description: 	reads the colormap of a GIF/GZF image.
* In: 
*	plc:		current PLC
*	gif:		plc image object.
* Returns:
*	True when colormap has been read, False if not.
*****/
static Boolean
ReadColormap(PLC *plc, PLCImageGIF *gif)
{
	register int i;
	Byte rgb[3];

	_XmHTMLDebug(15, ("plc.c: ReadColormap for %s\n", plc->url));

	/* read it */
	for(i = 0; i < gif->cmapsize; ++i)
	{
		if(!_PLCReadOK(plc, rgb, sizeof(rgb)))
			return(False);

		GETR(gif->cmap[i]) = rgb[0];
		GETG(gif->cmap[i]) = rgb[1];
		GETB(gif->cmap[i]) = rgb[2];
	}
	return(True);
}
Exemplo n.º 15
0
void do_bumpmapping(BITMAP *dest, BITMAP *bumpmap, BITMAP *colormap, int light_x, int light_y)
{
 int x, y, nx, ny, lx, ly, c;
 float k;

 for(y = 1; y < bumpmap->h - 1; y++)
  for(x = 1; x < bumpmap->w - 1; x++)
   {
    nx = PIXEL(bumpmap, x + 1, y) - PIXEL(bumpmap, x - 1, y);
    ny = PIXEL(bumpmap, x, y + 1) - PIXEL(bumpmap, x, y - 1);
    lx = x - light_x - 128;
    ly = y - light_y - 128;
    nx -= lx;
    ny -= ly;
    clamp(&nx, 0, 255);
    clamp(&ny, 0, 255);

    c = PIXEL(colormap, x, y);
    k = envmap[nx][ny] * 0.00390625;

    PIXEL(dest, x, y) = MAKECOL(GETR(c) * k, GETG(c) * k, GETB(c) * k);
  }
}
Exemplo n.º 16
0
void ObjectPool::SetBWbools(const char* filename, int NumOfObject)
{
	HGE *hge = hgeCreate(HGE_VERSION);
	HTEXTURE pic = hge->Texture_Load(filename);
	int width = hge->Texture_GetWidth(pic);
	int height = hge->Texture_GetHeight(pic);
	BWpic bwpic;
	bwpic.width = width;
	bwpic.height = height;
	bwpic.bools = (bool**)malloc(sizeof(bool*)*width);
	for (int i = 0; i < width; i++)
		bwpic.bools[i] = (bool*)malloc(sizeof(bool)*height);
	DWORD *color = hge->Texture_Lock(pic);
	for (int i = 0; i < width; i++)
	for (int j = 0; j < height;j++)	
	if (GETR(color[j*width + i]) == 0 && GETG(color[j*width + i]) == 0 && GETB(color[j*width + i]) == 0)
		bwpic.bools[j][i] = true;
	else bwpic.bools[j][i] = false;
	bwpic.number = NumOfObject;
	hge->Texture_Unlock(pic);
	hge->Texture_Free(pic);
	BWpics.push_back(bwpic);
	BWpics.shrink_to_fit();
}
Exemplo n.º 17
0
void d3d_vertex_color(gs_scalar x, gs_scalar y, gs_scalar z, int color, double alpha) {
    glColor4f(GETR(color), GETG(color), GETB(color), alpha);
    glVertex3d(x,y,z);
    glColor4ubv(enigma::currentcolor);
}
Exemplo n.º 18
0
//上传一个block作为tmpfile
void uploadblock(block *tb)
{
    block b = *tb;
    free(tb);
    char buff[1024];
    snprintf(buff, sizeof(buff) - 1,
             "https://c.pcs.baidu.com/rest/2.0/pcs/file?"
             "method=upload&"
             "access_token=%s&"
             "type=tmpfile"
             , Access_Token);

    Http *r = Httpinit(buff);

    if (r == NULL) {
        errorlog("can't resolve domain:%s\n", strerror(errno));
        goto ret;
    }

    FILE *tpfile = tmpfile();
    if (!tpfile) {
        errorlog("create temp file error:%s\n", strerror(errno));
        goto ret;
    }

    char *buf = (char *)malloc(GetWriteBlkSize(b.bno));
    buffstruct bs = {0, GetWriteBlkSize(b.bno), buf};
    pthread_mutex_lock(&b.fd->lock);
    lseek(b.fd->file, GetWriteBlkStartPoint(b.bno), SEEK_SET);
    bs.len = read(b.fd->file, bs.buf, bs.len);
    CLRR(b.fd->cache.w.flags, b.bno);
    pthread_mutex_unlock(&b.fd->lock);

    r->method = post_formdata;
    r->readfunc = readfrombuff;
    r->readprame = &bs;
    r->length = bs.len;
    r->writefunc = savetofile;
    r->writeprame = tpfile;

    if ((errno = request(r)) != CURLE_OK) {
        errorlog("network error:%d\n", errno);
        free(buf);
        Httpdestroy(r);
        fclose(tpfile);
        goto ret;
    }
    free(buf);
    Httpdestroy(r);

    json_object * json_get = json_object_from_FILE(tpfile);
    fclose(tpfile);

    if (json_get == NULL) {
        errorlog("json_object_from_FILE filed!\n");
        goto ret;
    }

    json_object *jerror_code;
    if (json_object_object_get_ex(json_get, "error_code", &jerror_code)) {
        json_object *jerror_msg;
        json_object_object_get_ex(json_get, "error_msg", &jerror_msg);
        errorlog("api error:%s\n", json_object_get_string(jerror_msg));
        json_object_put(json_get);
        goto ret;
    }

    json_object *jmd5;
    if (json_object_object_get_ex(json_get, "md5",&jmd5)) {
        pthread_mutex_lock(&b.fd->lock);
        if (GETR(b.fd->cache.w.flags, b.bno)) {
            CLRR(b.fd->cache.w.flags, b.bno);
        } else {
            strcpy(b.fd->cache.w.md5[b.bno], json_object_get_string(jmd5));
            CLRD(b.fd->cache.w.flags, b.bno);
            CLRZ(b.fd->cache.w.flags, b.bno);
            if (b.bno)
                sem_post(&wcache);
        }
        b.fd->cache.w.taskid[b.bno] = 0;
        pthread_mutex_unlock(&b.fd->lock);
        json_object_put(json_get);
        return;
    } else {
        errorlog("Did not get MD5:%s\n", json_object_to_json_string(json_get));
    }
ret:
    pthread_mutex_lock(&b.fd->lock);
    b.fd->cache.w.taskid[b.bno] = 0;
    pthread_mutex_unlock(&b.fd->lock);
}
Exemplo n.º 19
0
void CALL BSGL_Impl::Gfx_Clear(DWORD color) {
    glClearColor((GLfloat)GETR(color), (GLfloat)GETG(color),
                 (GLfloat)GETB(color), (GLfloat)GETA(color));
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
}
Exemplo n.º 20
0
void CConvertYuvToRgb::Convert(DWORD dwWidth,DWORD dwHeight,DWORD dwYStride,DWORD dwUVStride,LPBYTE lpY,LPBYTE lpU,LPBYTE lpV,LPBYTE lpOutput,int rPos,int gPos,int bPos)
{
	int       i,j,k,m;
	int       nWidthUV;
	int       nHeightUV;
	int       nPosUV;
	int       nWidth;
	int       nWidth3;
	BYTE      kY;
	BYTE      kU;
	BYTE      kV;
	LPBYTE    lpInPos;

	if(dwYStride==0)
		dwYStride = dwWidth;

	if(dwUVStride==0)
		dwUVStride = dwWidth/2;

	lpInPos   = lpOutput;
	nWidthUV  = dwWidth/2;
	nHeightUV = dwHeight/2;
	nWidth    = dwWidth;
	nWidth3   = 3*dwWidth;
	nPosUV    = 0;
	k         = 0;
	m         = 0;

	for(j=0;j<nHeightUV;j++)
	{
		for(i=0;i<nWidthUV;i++)
		{
			kV = lpV[nPosUV];
			kU = lpU[nPosUV];

			kY = lpY[k];
			lpInPos[m+bPos] = GETB(kY,kV);
			lpInPos[m+gPos] = GETG(kY,kU,kV);
			lpInPos[m+rPos] = GETR(kY,kU);

			kY = lpY[k+1];
			lpInPos[m+bPos+3] = GETB(kY,kV);
			lpInPos[m+gPos+3] = GETG(kY,kU,kV);
			lpInPos[m+rPos+3] = GETR(kY,kU);

			kY = lpY[k+dwYStride];
			lpInPos[m+nWidth3+bPos] = GETB(kY,kV);
			lpInPos[m+nWidth3+gPos] = GETG(kY,kU,kV);
			lpInPos[m+nWidth3+rPos] = GETR(kY,kU);

			kY = lpY[k+1+dwYStride];
			lpInPos[m+nWidth3+bPos+3] = GETB(kY,kV);
			lpInPos[m+nWidth3+gPos+3] = GETG(kY,kV,kV);
			lpInPos[m+nWidth3+rPos+3] = GETR(kY,kU);

			m += 6;
			k += 2;
			nPosUV++;
		}

		k      += ((dwYStride - nWidth) + dwYStride); //(dwYStride - nWidth) учитываем выравнивание в первой строке (которую прошли)
		nPosUV += (dwUVStride - nWidthUV); //Учитываем выравнивание, если оно было
		m      += nWidth3;
	}
}
Exemplo n.º 21
0
void d3d_vertex_color(double x, double y, double z, int color, double alpha)
{
    glColor4f(GETR(color), GETG(color), GETB(color), alpha);
    glVertex3d(x,y,z);
    glColor4ubv(enigma::currentcolor);
}
Exemplo n.º 22
0
HTEXTURE HGE_CALL HGE_Impl::Texture_Load(const char *filename, hgeU32 size, bool bMipmap)
{
	HRESULT hr;

	void *data;
	hgeU32 _size;
	ID3D11Resource* pRes;
	ID3D11Resource* pStagingRes;
	ID3D11Texture2D* pTex;
	ID3D11ShaderResourceView* pSRV;
	//D3DXIMAGE_INFO info;
	CTextureList *texItem;

	//load file to buffer
	if (size)
	{
		//If argument is already the buffer
		data = (void *)filename; _size = size;
	}
	else
	{
		data = pHGE->Resource_Load(filename, &_size);
		if (!data) return NULL;
	}

	//Get image info
	D3DX11_IMAGE_INFO imgInfo;
	hr = D3DX11GetImageInfoFromMemory(
		(LPCSTR)data,
		_size,
		NULL,
		&imgInfo,
		NULL);
	if (hr)
	{
		_PostError("Cannot get image info.\n");
		if (!size) Resource_Free(data);
		return NULL;
	}

	D3DX11_IMAGE_LOAD_INFO loadImgInfo;
	loadImgInfo.MipLevels = bMipmap ? 0 : 1;
	loadImgInfo.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	loadImgInfo.Usage = D3D11_USAGE_STAGING;
	loadImgInfo.BindFlags = 0;// (autogen) ? (D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET) : (D3D11_BIND_SHADER_RESOURCE);
	loadImgInfo.CpuAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
	loadImgInfo.MiscFlags = 0;

	//Create Staging texture first
	hr = D3DX11CreateTextureFromMemory(
		m_pD3DDevice,
		(LPCVOID)data,
		_size,
		&loadImgInfo,
		NULL,
		&pStagingRes,
		0);
	if (hr)
	{
		_PostError("Can't create texture");
		if (!size) Resource_Free(data);
		return NULL;
	}

	//shouldn't access the file buffer anymore
	if (!size) Resource_Free(data);

	//Convert 0xFF00FFFF to transparent color
	D3D11_TEXTURE2D_DESC TDesc;
	((ID3D11Texture2D*)pStagingRes)->GetDesc(&TDesc);
	if (bUseTransparentColor)
	{
		DWORD* pLockPtr = (DWORD*)Texture_Lock((HTEXTURE)pStagingRes, false);

		int end = TDesc.Width * TDesc.Height;
		for (int i = 0; i < end; i++)
		{
			DWORD& currentPixel = pLockPtr[i];

			if (GETR(currentPixel) == 0xFF &&
				GETG(currentPixel) == 0x00 &&
				GETB(currentPixel) == 0xFF)
			{
				currentPixel = ARGB(0x00, 0x00, 0x00, 0x00);
			}

		}
		//Create default texture with data
		//from the staging texture
		TDesc.Usage = D3D11_USAGE_DEFAULT;
		TDesc.CPUAccessFlags = 0;
		TDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
		TDesc.MipLevels = bMipmap ? 0 : 1;

		D3D11_SUBRESOURCE_DATA sr;
		sr.pSysMem = pLockPtr;
		sr.SysMemPitch = TDesc.Width * 4;
		sr.SysMemSlicePitch = TDesc.Width * TDesc.Height * 4;

		hr = m_pD3DDevice->CreateTexture2D(&TDesc, &sr, &pTex);
		if (hr)
		{
			_PostError("Can't create texture");
			if (!size) Resource_Free(data);
			pStagingRes->Release();
			return NULL;
		}
		Texture_Unlock((HTEXTURE)pStagingRes);
		SAFE_RELEASE(pStagingRes);
	}

	D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc;
	memset(&SRVDesc, 0, sizeof(SRVDesc));
	SRVDesc.Format = TDesc.Format;
	SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
	SRVDesc.Texture2D.MipLevels = bMipmap ? 0 : 1;

	hr = m_pD3DDevice->CreateShaderResourceView(pTex, &SRVDesc, &pSRV);
	if (hr)
	{
		_PostError("Can't create texture");
		if (!size) Resource_Free(data);
		return NULL;
	}

	pSRV->GetResource(&pRes);

	// 	hr = CreateWICTextureFromMemory(
	// 		pd3dDevice,
	// 		pd3dImmediateContext,
	// 		(uint8_t*)data,
	// 		_size,
	// 		&pRes,
	// 		&pSRV,
	// 		0);

	texItem = new CTextureList;
	texItem->tex = (HTEXTURE)pTex;
	texItem->m_pSRV = pSRV;
	texItem->width = TDesc.Width;
	texItem->height = TDesc.Height;
	texItem->next = textures;
	textures = texItem;
	return (HTEXTURE)texItem;
}
Exemplo n.º 23
0
void Render(void)
{
	static int sn = 0;

	if (params.antiFlicker)
	{
		renderSurf = scrSurf[sn];
		sn = 1 - sn;
	} else renderSurf = screen;

	if ((drawFrame || isAvgImageWrited /* isLongImageWrited */) && SDL_MUSTLOCK(renderSurf))
	{
		if (SDL_LockSurface(renderSurf) < 0)
		{
			printf("Can't lock surface\n");
			return;
		}
	}

	renderPitch = renderSurf->pitch / 4;

	if (dev_extport.Is16Colors()) renderPtr = Render16c;
	else if (dev_extport.IsMulticolor()) renderPtr = RenderMulticolor;
//	else if (dev_extport.Is512x192()) renderPtr = Render512x192;
//	else if (dev_extport.Is384x304()) renderPtr = Render384x304;
	else renderPtr = RenderSpeccy;

	InitActClk();
	prevRenderClk = 0;

	while (cpuClk < INT_LENGTH)
	{
		CpuStep();
		CpuInt();
	}

	if (drawFrame || isAvgImageWrited /* isLongImageWrited */)
	{
		while (cpuClk < MAX_FRAME_TACTS)
		{
			CpuStep();
			renderPtr(cpuClk);
		}
	}
	else
	{
		while (cpuClk < MAX_FRAME_TACTS) {
			CpuStep();
		}
	}

	renderPtr = NULL;
	lastDevClk = devClk;
	cpuClk -= MAX_FRAME_TACTS;
	devClk = cpuClk;

	if ((drawFrame || isAvgImageWrited /* isLongImageWrited */) && SDL_MUSTLOCK(renderSurf)) SDL_UnlockSurface(renderSurf);
	if (params.antiFlicker && (drawFrame || isAvgImageWrited /* isLongImageWrited */)) AntiFlicker(renderSurf, scrSurf[sn]);

	// if (isLongImageWrited)
	// {
	//	int * src = (int *)screen->pixels + (PITCH * (32 + longImagePos)) + 32;
	//
	//	for (int i = 256; i--;)
	//	{
	//		unsigned int c = *src;
	//		int r = GETR(c);
	//		int g = GETG(c);
	//		int b = GETB(c);
	//
	//		longImageFile.PutBYTE(r);
	//		longImageFile.PutBYTE(g);
	//		longImageFile.PutBYTE(b);
	//
	//		*(src++) = DRGB(255 - r, 255 - g, 255 - b);
	//	}
	//
	//	longImageHeight++;
	//	longImagePos = (longImagePos + 1) % 192;
	// }

	if (isAvgImageWrited)
	{
		int * src = (int *)screen->pixels;
		long * dst = avgImageBuffer;

		for (int i = HEIGHT; i--;)
		{
			int * line = src;

			for (int j = WIDTH; j--;)
			{
				unsigned int c = *(line++);

				*(dst++) += (long)GETR(c);
				*(dst++) += (long)GETG(c);
				*(dst++) += (long)GETB(c);
			}

			src += PITCH;
		}

		// avgImageFrames++;
	}
}