Esempio n. 1
0
BOOL mfc_render_init(HWND hWnd)
{
	DDSURFACEDESC    ddsd;
	DDCAPS           ddcaps;

	HRESULT          hRet;

	///////////////////////////////////////////////////////////////////////////
	// Create the main DirectDraw object
	///////////////////////////////////////////////////////////////////////////
	hRet = DirectDrawCreate(NULL, &g_pDD, NULL);
	if (hRet != DD_OK)
		return PRINT_ERRMSG(TEXT("DirectDrawCreate FAILED"));

	// Get exclusive mode
	hRet = g_pDD->SetCooperativeLevel(hWnd, DDSCL_NORMAL);
	if (hRet != DD_OK)
		return PRINT_ERRMSG(TEXT("SetCooperativeLevel FAILED"));


	// Get a primary surface interface pointer (only needed for init.)

	memset(&ddsd, 0, sizeof(ddsd));
	ddsd.dwSize = sizeof(ddsd);
	ddsd.dwFlags = DDSD_CAPS;
	ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
	hRet = g_pDD->CreateSurface(&ddsd, &g_pDDSPrimary, NULL);
	if (hRet != DD_OK)
		return PRINT_ERRMSG(TEXT("CreateSurface FAILED"));

	// See if we can support overlays.
	memset(&ddcaps, 0, sizeof(ddcaps));
	ddcaps.dwSize = sizeof(ddcaps);
	hRet = g_pDD->GetCaps(&ddcaps, NULL);
	if (hRet != DD_OK)
		return PRINT_ERRMSG(TEXT("GetCaps FAILED"));

	if (ddcaps.dwOverlayCaps == 0)
		return PRINT_ERRMSG(TEXT("Overlays are not supported in hardware!"));


	// SW YUV->RGB conversion table initialization
	_initConvTab();

	return TRUE;
}
Esempio n. 2
0
extern "C" unsigned char rglswCreateWindow(GLint ihwnd, GLint width)
{
    DDSURFACEDESC ddsd;
    HRESULT       ddrval;
    DDPIXELFORMAT pix;
    DDSCAPS       ddscaps;
    DDCAPS        ddcaps;
    HWND          hWnd = (HWND)ihwnd;

    SCRWIDTH = width;
    switch (width)
    {
    case 1600:
        SCRHEIGHT = 1200;
        break;
    case 1280:
        SCRHEIGHT = 1024;
        break;
    case 1024:
        SCRHEIGHT = 768;
        break;
    case 800:
        SCRHEIGHT = 600;
        break;
    default:
        SCRWIDTH  = 640;
        SCRHEIGHT = 480;
    }

    hwnd = hWnd;

    ddrval = DirectDrawCreate(NULL, &lpDD, NULL);
    if (ddrval != DD_OK)
    {
        return FALSE;
    }

    ZeroMemory(&ddcaps, sizeof(ddcaps));
    ddcaps.dwSize = sizeof(ddcaps);
    lpDD->GetCaps(&ddcaps, NULL);

    if (WINDOWED)
    {
        ddrval = lpDD->SetCooperativeLevel(hwnd, DDSCL_NORMAL);
        if (ddrval != DD_OK)
        {
            return FALSE;
        }
    }
    else
    {
        ddrval = lpDD->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
        if (ddrval != DD_OK)
        {
            return FALSE;
        }

        ddrval = lpDD->SetDisplayMode(SCRWIDTH, SCRHEIGHT, 16);
        if (ddrval != DD_OK)
        {
            return FALSE;
        }
    }

    ZeroMemory(&ddsd, sizeof(ddsd));
    ddsd.dwSize = sizeof(ddsd);
    if (WINDOWED)
    {
        ddsd.dwFlags = DDSD_CAPS;
        ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
        ddrval = lpDD->CreateSurface(&ddsd, &PrimarySurface, NULL);
    }
    else
    {
        ddsd.dwFlags = DDSD_CAPS;
        ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
        ddrval = lpDD->CreateSurface(&ddsd, &PrimarySurface, NULL);
    }
    if (ddrval != DD_OK)
    {
        return FALSE;
    }

    ZeroMemory(&ddsd, sizeof(ddsd));
    ddsd.dwSize = sizeof(ddsd);
    ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
    ddsd.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY;
    ddsd.dwWidth = SCRWIDTH;
    ddsd.dwHeight = SCRHEIGHT;
    ddrval = lpDD->CreateSurface(&ddsd, &BackSurface, NULL);
    if (ddrval != DD_OK)
    {
        ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
        ddrval = lpDD->CreateSurface(&ddsd, &BackSurface, NULL);
    }
    if (ddrval != DD_OK)
    {
        return FALSE;
    }

    pix.dwSize = sizeof(pix);
    pix.dwFlags = DDPF_RGB;
    BackSurface->GetPixelFormat(&pix);

    if (pix.dwRBitMask == 0x7C00)
    {
        depth = 15;
    }
    else
    {
        depth = 16;
    }

    bActive = TRUE;

    if (useDirectDraw)
    {
        scratch_pitch = GetPitch();
        scratch_buffer_2 = NULL;
    }
    else
    {
        depth = 15;
        scratch_pitch = 2*SCRWIDTH;
        scratch_buffer_2 = (BYTE*)malloc(scratch_pitch*SCRHEIGHT);
    }
    scratch_buffer = (BYTE*)malloc(scratch_pitch*SCRHEIGHT);
    memset(scratch_buffer, 0, scratch_pitch*SCRHEIGHT);

    clear_buffers();

    return TRUE;
}
Esempio n. 3
0
extern "C" HRESULT
InitDirectDraw(HWND hWnd, int w, int h, void* pixelData)
{
    WNDCLASS                    wc;
    DDSURFACEDESC               ddsd;
    HRESULT                     hRet;

    hRet = DirectDrawCreate(NULL, &g_pDD, NULL);
    if (hRet != DD_OK)
        return InitFail(hWnd, hRet, szDDrawFailedMsg);

    // Get exclusive mode
    hRet = g_pDD->SetCooperativeLevel(hWnd, DDSCL_FULLSCREEN); //DDSCL_NORMAL);//
    if (hRet != DD_OK)
        return InitFail(hWnd, hRet, szSetCooperativeFailMsg);

#if 0
	DDCAPS ddCaps;
    DDCAPS ddHelCaps;

    g_pDD->GetCaps(&ddCaps, &ddHelCaps);
    if (!(ddCaps.ddsCaps.dwCaps & DDSCAPS_BACKBUFFER)) 
    {
        return InitFail(hWnd, E_FAIL, szNoBackBufferMsg);
    }

    if (!(ddCaps.ddsCaps.dwCaps & DDSCAPS_FLIP)) 
    {
        return InitFail(hWnd, E_FAIL, szNoFlipSurfacesMsg);
    }
#endif
    // Create the primary surface with 1 back buffer
    memset(&ddsd, 0, sizeof(ddsd));
    ddsd.dwSize = sizeof(ddsd);
    ddsd.dwFlags = DDSD_CAPS;// | DDSD_BACKBUFFERCOUNT;
    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
						 //| DDSCAPS_FLIP;
    
	//ddsd.dwBackBufferCount = 1;

    hRet = g_pDD->CreateSurface(&ddsd, &g_pDDSPrimary, NULL);
    if (hRet != DD_OK)
    {
        return InitFail(hWnd, hRet, szCreateSurfaceFailMsg);
    }

	DWORD dwID;
	g_hRefreshScreen = CreateEvent(NULL, FALSE, FALSE, NULL);
	CreateThread(NULL, 0, ScreenRefresThread, NULL, 0, &dwID);
	return DD_OK;

#if 0
#define WIDTH  w // in pixels
#define HEIGHT h
#define DEPTH  2  // in bytes (2 bytes == 16 bits)
	if (ddsd.dwBackBufferCount > 0) {
		hRet = g_pDDSPrimary->EnumAttachedSurfaces(&g_pDDSBack, EnumFunction);
		if (hRet != DD_OK)
			return InitFail(hWnd, hRet, szEnumAttachedSurfacesFailMsg);
	}

	ZeroMemory(&ddsd, sizeof(DDSURFACEDESC));
    ZeroMemory(&ddsd.ddpfPixelFormat, sizeof(DDPIXELFORMAT));
    ddsd.dwSize = sizeof(ddsd);

	hRet = g_pDDSBack->Lock(NULL, &ddsd, DDLOCK_WAITNOTBUSY, NULL);
	g_pDDSPrimary->Unlock(NULL);

    ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_LPSURFACE |
                    DDSD_PITCH | DDSD_PIXELFORMAT;
    ddsd.dwWidth = WIDTH;
    ddsd.dwHeight= HEIGHT;
    //ddsd.lPitch  = (LONG)DEPTH * WIDTH;
    ddsd.lpSurface = pixelData;
 /*
    // Set up the pixel format for 24-bit RGB (8-8-8).
    ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
    ddsd.ddpfPixelFormat.dwFlags= DDPF_RGB;
    ddsd.ddpfPixelFormat.dwRGBBitCount = (DWORD)DEPTH*8;
	ddsd.ddpfPixelFormat.dwRBitMask = 0xF800;//surface->format->Rmask;
	ddsd.ddpfPixelFormat.dwGBitMask = 0x07E0;//surface->format->Gmask;
	ddsd.ddpfPixelFormat.dwBBitMask = 0x001F;//surface->format->Bmask;
    //ddsd.ddpfPixelFormat.dwRBitMask    = 0x00FF0000;
    //ddsd.ddpfPixelFormat.dwGBitMask    = 0x0000FF00;
    //ddsd.ddpfPixelFormat.dwBBitMask    = 0x000000FF;
 */
    // Create the surface
    hRet = g_pDD->CreateSurface(&ddsd, &g_pDDSBack, NULL);
	if (hRet != DD_OK)
		return InitFail(hWnd, hRet, szEnumAttachedSurfacesFailMsg);
	return DD_OK;
#endif

	if (ddsd.dwBackBufferCount > 0) {
		hRet = g_pDDSPrimary->EnumAttachedSurfaces(&g_pDDSBack, EnumFunction);
		if (hRet != DD_OK)
			return InitFail(hWnd, hRet, szEnumAttachedSurfacesFailMsg);
	}

	return DD_OK;

#if 1
	ddsd.dwSize = sizeof(ddsd);
	ddsd.dwFlags = (DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS |
					DDSD_PITCH | DDSD_LPSURFACE | DDSD_PIXELFORMAT);
	ddsd.dwWidth = w;
	ddsd.dwHeight= h;
#if defined(NONAMELESSUNION)
	ddsd.u1.lPitch = SDL_CalculatePitch(w, 2);;
#else
	ddsd.lPitch = SDL_CalculatePitch(w, 2);;
#endif
	ddsd.lpSurface = pixelData;

	const int SDL_HWSURFACE = 1;
	int flag = 1;

	if ( (flag & SDL_HWSURFACE) == SDL_HWSURFACE ) {
		ddsd.ddsCaps.dwCaps =
				(/*DDSCAPS_OFFSCREENPLAIN | */DDSCAPS_VIDEOMEMORY);
	} else {
		ddsd.ddsCaps.dwCaps =
				(/*DDSCAPS_OFFSCREENPLAIN | */DDSCAPS_SYSTEMMEMORY);
	}

	ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
	ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
//	if ( surface->format->palette ) {
//		ddsd.ddpfPixelFormat.dwFlags |= DDPF_PALETTEINDEXED8;
//	}
#if defined(NONAMELESSUNION)
	ddsd.ddpfPixelFormat.u1.dwRGBBitCount = surface->format->BitsPerPixel;
	ddsd.ddpfPixelFormat.u2.dwRBitMask = surface->format->Rmask;
	ddsd.ddpfPixelFormat.u3.dwGBitMask = surface->format->Gmask;
	ddsd.ddpfPixelFormat.u4.dwBBitMask = surface->format->Bmask;
#else
	ddsd.ddpfPixelFormat.dwRGBBitCount = 16;//surface->format->BitsPerPixel;
	ddsd.ddpfPixelFormat.dwRBitMask = 0xF800;//surface->format->Rmask;
	ddsd.ddpfPixelFormat.dwGBitMask = 0x07E0;//surface->format->Gmask;
	ddsd.ddpfPixelFormat.dwBBitMask = 0x001F;//surface->format->Bmask;
#endif

	/* Create the DirectDraw video surface */
	//if ( requested != NULL ) {
	//	g_pDDSOne = requested;
	//} else 
	{
		hRet = g_pDD->CreateSurface(&ddsd, &g_pDDSBack, NULL); 
#if 0
		if ( hRet != DD_OK ) {
			SetDDerror("DirectDraw2::CreateSurface", hRet);
			goto error_end;
		}
		hRet = g_pDDSBack->QueryInterface(
			&IID_IDirectDrawSurface3, (LPVOID *)&g_pDDSOne);
		g_pDDSBack->Release();
		if ( hRet != DD_OK ) {
			SetDDerror("DirectDrawSurface::QueryInterface", hRet);
			goto error_end;
		}
#endif
	}
#if 0
	if ( (flag & SDL_HWSURFACE) == SDL_HWSURFACE ) {
		/* Check to see whether the surface actually ended up
		   in video memory, and fail if not.  We expect the
		   surfaces we create here to actually be in hardware!
		*/
		hRet = g_pDDSOne->GetCaps(&ddsd.ddsCaps);
		if ( hRet != DD_OK ) {
			//SetDDerror("DirectDrawSurface3::GetCaps", hRet);
			goto error_end;
		}
		if ( (ddsd.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY) !=
							DDSCAPS_VIDEOMEMORY ) {
			//SDL_SetError("No room in video memory");
			goto error_end;
		}
	} else {
		/* Try to hook our surface memory */
		ddsd.dwFlags = DDSD_LPSURFACE;
		ddsd.lpSurface = pixelData;//surface->pixels;
		hRet = g_pDDSOne->SetSurfaceDesc(
								&ddsd, 0);
		if ( hRet != DD_OK ) {
			//SetDDerror("DirectDraw2::SetSurfaceDesc", hRet);
			goto error_end;
		}
	
	}

	/* Make sure the surface format was set properly */
	SDL_memset(&ddsd, 0, sizeof(ddsd));
	ddsd.dwSize = sizeof(ddsd);
	hRet = IDirectDrawSurface3_Lock(g_pDDSOne, NULL,
		&ddsd, (DDLOCK_NOSYSLOCK|DDLOCK_WAIT), NULL);
	if ( hRet != DD_OK ) {
		//SetDDerror("DirectDrawSurface3::Lock", hRet);
		goto error_end;
	}
	IDirectDrawSurface3_Unlock(g_pDDSOne, NULL);

	if ( (flag & SDL_HWSURFACE) == SDL_SWSURFACE ) {
		if ( ddsd.lpSurface != surface->pixels ) {
			//SDL_SetError("DDraw didn't use SDL surface memory");
			goto error_end;
		}
		if (
#if defined(NONAMELESSUNION)
			ddsd.u1.lPitch
#else
			ddsd.lPitch
#endif
				 != (LONG)surface->pitch ) {
			//SDL_SetError("DDraw created surface with wrong pitch");
			goto error_end;
		}
	} else {
#if defined(NONAMELESSUNION)
		surface->pitch = (Uint16)ddsd.u1.lPitch;
#else
		surface->pitch = (Uint16)ddsd.lPitch;
#endif
	}
#if defined(NONAMELESSUNION)
	if ( (ddsd.ddpfPixelFormat.u1.dwRGBBitCount != 
					surface->format->BitsPerPixel) ||
	     (ddsd.ddpfPixelFormat.u2.dwRBitMask != surface->format->Rmask) ||
	     (ddsd.ddpfPixelFormat.u3.dwGBitMask != surface->format->Gmask) ||
	     (ddsd.ddpfPixelFormat.u4.dwBBitMask != surface->format->Bmask) ){
#else
	if ( (ddsd.ddpfPixelFormat.dwRGBBitCount != 
					surface->format->BitsPerPixel) ||
	     (ddsd.ddpfPixelFormat.dwRBitMask != surface->format->Rmask) ||
	     (ddsd.ddpfPixelFormat.dwGBitMask != surface->format->Gmask) ||
	     (ddsd.ddpfPixelFormat.dwBBitMask != surface->format->Bmask) ){
#endif
		//SDL_SetError("DDraw didn't use SDL surface description");
		goto error_end;
	}
	if ( (ddsd.dwWidth != (DWORD)surface->w) ||
		(ddsd.dwHeight != (DWORD)surface->h) ) {
		//SDL_SetError("DDraw created surface with wrong size");
		goto error_end;
	}

	/* Set the surface private data */
	surface->flags |= flag;
	surface->hwdata->dd_surface = g_pDDSOne;
	if ( (surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
		LPDIRECTDRAWSURFACE3 dd_writebuf;

		ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
		hRet = IDirectDrawSurface3_GetAttachedSurface(g_pDDSOne,
						&ddsd.ddsCaps, &dd_writebuf);
		if ( hRet != DD_OK ) {
			//SetDDerror("DirectDrawSurface3::GetAttachedSurface",
								hRet);
		} else {