Advertisement

How do I do this DDRAW operation in OpenGL?

Started by November 06, 2004 05:14 PM
10 comments, last by vichollis 20 years, 3 months ago
I have this:
IDirectDrawSurface7 * DXC_ddraw::pCreateOffScreenSurface(WORD wSzX, WORD wSzY)
{
	DDSURFACEDESC2 ddsd;
	IDirectDrawSurface7 * pdds4;

    ZeroMemory(&ddsd, sizeof(ddsd));
	if ((wSzX % 4) != 0) wSzX += 4 - (wSzX % 4);
    ddsd.dwSize  = sizeof(ddsd);
    ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT |DDSD_WIDTH;
	ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
	ddsd.dwWidth  = (DWORD)wSzX;
    ddsd.dwHeight = (DWORD)wSzY;
    if (m_lpDD4->CreateSurface(&ddsd, &pdds4, NULL) != DD_OK) return NULL;
	return pdds4;
}
As you can see, I created a plain buffer in DirectDraw. How would I go about doing this in OpenGL? Another question...I'm pretty sure OpenGL lets me do this more easily, but here we go.

void DXC_ddraw::ChangeDisplayMode(HWND hWnd)
{
	HRESULT        ddVal;
	DDSURFACEDESC2 ddsd;

	if (m_lpBackB4flip != NULL)
	{
		m_lpBackB4flip->Release();
		m_lpBackB4flip = NULL;
	}
	if (m_lpBackB4 != NULL) m_lpBackB4->Release();
	if (m_lpFrontB4 != NULL) m_lpFrontB4->Release();
	if (m_lpDD4 != NULL)
	{
		if (m_bFullMode == TRUE) m_lpDD4->RestoreDisplayMode();
	}

	if( m_bFullMode == TRUE )
	{
		int cx = GetSystemMetrics(SM_CXFULLSCREEN);
		int cy = GetSystemMetrics(SM_CYFULLSCREEN);

		ddVal = m_lpDD4->SetCooperativeLevel(hWnd, DDSCL_NORMAL);
		if (ddVal != DD_OK) return;

		cx = cx/2;
		cy = cy/2;
		if(cy>280) cy -= 40;
		SetWindowPos( hWnd, NULL, cx-320, cy-240, 640, 480, SWP_SHOWWINDOW);

		// Create Front Buffer
		memset( (VOID *)&ddsd, 0, sizeof(ddsd) );
		ddsd.dwSize = sizeof( ddsd );
		ddsd.dwFlags = DDSD_CAPS;
		//ddsd.dwBackBufferCount = 0;
		ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
		
		ddVal = m_lpDD4->CreateSurface(&ddsd, &m_lpFrontB4, NULL);
		if (ddVal != DD_OK) return;

		SetRect(&m_rcFlipping, cx-320, cy-240, cx+320, cy+240); // our fictitious sprite bitmap is... 
		m_bFullMode = FALSE;
	}
	else
	{
		DDSCAPS2       ddscaps;
		// Full Screen Mode
		ddVal = m_lpDD4->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
		if (ddVal != DD_OK) return;

		ddVal = m_lpDD4->SetDisplayMode(640, 480, 16,0,0);
		if (ddVal != DD_OK) return;
		//Create Front Buffer
		memset( (VOID *)&ddsd, 0, sizeof(ddsd) );
		ddsd.dwSize = sizeof( ddsd );
		ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
		ddsd.dwBackBufferCount = 1;//2; //v1.3
		ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
		
		ddVal = m_lpDD4->CreateSurface(&ddsd, &m_lpFrontB4, NULL);
		if (ddVal != DD_OK) return;

// Learned from:
// http://www.gamedev.net/reference/articles/article608.asp

		ZeroMemory(&ddscaps, sizeof(ddscaps));
		ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
		ddVal = m_lpFrontB4->GetAttachedSurface(&ddscaps, &m_lpBackB4flip);
		if (ddVal != DD_OK) return;
		SetRect(&m_rcFlipping, 0, 0, 640, 480); // our fictitious sprite bitmap is... 
		m_bFullMode = TRUE;
	}
	InitFlipToGDI(hWnd);
	// Create Back Buffer
	m_lpBackB4 = pCreateOffScreenSurface(640, 480);
	if (m_lpBackB4 == NULL) return;

	// Pre-draw background surface create buffer 
	m_lpPDBGS = pCreateOffScreenSurface(640+32, 480+32);
	if (m_lpPDBGS == NULL) return;

	// Getting the back buffer's address and pitch
 
	ddsd.dwSize = sizeof(ddsd);
	if (m_lpBackB4->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL) != DD_OK) return;
	m_pBackB4Addr        = (WORD *)ddsd.lpSurface;
	m_sBackB4Pitch       = (short)ddsd.lPitch >> 1;
	m_lpBackB4->Unlock(NULL);
}
Please, how would this DDRAW code be like in OpenGL? Like if I were porting the whole thing to OpenGL.
im pretty shure that what your looking for is p buffers.
I learnd most from this page
http://www.codesampler.com/oglsrc.htm
Just scroll down to the "Off-screen Rendering Using Pixel Buffers" section(it's in the middle of the page).

For the other bit, well since i don't know d3d i can't tell what half of that code does.
But you could take a look at the nehe basecode, there are probobly some simmilar things in there.
Advertisement
Video mode change isn't done by OpenGL, it's done by compainion libraries, like glx wgl and agl. SDL and GLUT also do this (I think glut does it, doesn't it?)
Hi, thanks for the tips. As for GLUT doing it I hope it does it because it's what I intend to use.

My trip to http://www.codesampler.com/oglsrc.htm showed me that guy really likes freeglut. I can't use that on Mac OS X..sigh..
I just submitted a tutorial on pbuffers to NeHe. Hopefully it will be up soon and will shed some light on things for ya.

- Cheers
Vic
Advertisement
Hi Vic, if you want to, can you PM me tutorial? I'm working hard on this these days. ^_^ Thanks
Well its kinda big how about I just e-mail it?
I sent it to your yahoo account.
vichollis: Can you send it to my E-mail too?

This topic is closed to new replies.

Advertisement