MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / ddgr_dx_surf_InitVideo

Function ddgr_dx_surf_InitVideo

dd_grwin32/ddgrWin32DX.cpp:91–159  ·  view source on GitHub ↗

Initializes the display for use with the DX subsystem.

Source from the content-addressed store, hash-verified

89
90// Initializes the display for use with the DX subsystem.
91bool ddgr_dx_surf_InitVideo(ddgr_surface *sf) {
92 tDXSurface *dxsf;
93 DDSURFACEDESC ddsd;
94
95 // we need to create a primary surface from the display mode we set, and possibly a backbuffer if
96 // requested.
97 if (DX_DATA(vidrefs) == 0) {
98 HRESULT hres;
99 DDSCAPS ddscaps;
100
101 hres = DX_DATA(lpDD)->SetDisplayMode(sf->w, sf->h, sf->bpp);
102 if (hres != DD_OK) {
103 ddgr_PushError("Unable to set DirectDraw display mode (%d)\n", LOWORD(hres));
104 return false;
105 }
106
107 memset(&ddsd, 0, sizeof(ddsd));
108 ddsd.dwSize = sizeof(ddsd);
109 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
110 ddsd.dwBackBufferCount = 1;
111 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
112
113 hres = DX_DATA(lpDD)->CreateSurface(&ddsd, &DX_DATA(vidsurf.lpdds), NULL);
114 if (hres != DD_OK) {
115 ddgr_PushError("Unable to capture DirectDraw display surface (%d)\n", LOWORD(hres));
116 return false;
117 }
118
119 ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
120
121 hres = DX_DATA(vidsurf.lpdds)->GetAttachedSurface(&ddscaps, &DX_DATA(vidsurf.lpddsback));
122 if (hres != DD_OK) {
123 ddgr_PushError("Unable to capture DirectDraw display back surface (%d)\n", LOWORD(hres));
124 return false;
125 }
126 }
127
128 DX_DATA(vidrefs)++; // increment vidref count
129
130 dxsf = new tDXSurface;
131 dxsf->lpdds = DX_DATA(vidsurf.lpdds);
132
133 // this means that we are capturing the screen, not creating a screen.
134 // get the screen's width and height and bitdepth
135 if (sf->flags == 0) {
136 memset(&ddsd, 0, sizeof(ddsd));
137 ddsd.dwSize = sizeof(ddsd);
138 dxsf->lpdds->GetSurfaceDesc(&ddsd);
139 sf->w = ddsd.dwWidth;
140 sf->h = ddsd.dwHeight;
141 sf->bpp = ddsd.ddpfPixelFormat.dwRGBBitCount;
142 }
143
144 // we create a dummy surface for the screen's back buffer, or our accessable buffer
145 // specifying SURFFLAG_BACKBUFFER ensures that we create a GDI bitmap of size requested
146 // in 'sf' and it will be our renderable bitmap, or OUR primary render buffer
147 if (sf->flags & SURFFLAG_BACKBUFFER) {
148 // set our front buffer to this newly created surface and delete the gdi bitmap object

Callers 1

ddgr_surf_InitVideoFunction · 0.85

Calls 1

ddgr_PushErrorFunction · 0.85

Tested by

no test coverage detected