void draw_line_primitive ( LPD3DTLVERTEX vertices ) { HRESULT d3drval; // flush_primitives (); d3drval = IDirect3DDevice3_DrawPrimitive ( d3d.device3, D3DPT_LINELIST, D3DFVF_TLVERTEX, ( LPVOID ) vertices, ( DWORD ) 2, ( DWORD ) ( D3DDP_DONOTCLIP | D3DDP_DONOTUPDATEEXTENTS ) ) ; if ( d3drval != DD_OK ) { debug_log ( "Unable to draw primitive: %s", get_ddraw_error_message ( d3drval ) ); } else { number_of_d3d_lines_drawn++; } }
void draw_terrain_3d_buffered_polygons ( void ) { if ( vertex_buffer != -1 ) { // // Finalise the last vertex buffer used // unlock_d3d_alpha_vertex_buffer ( vertex_buffer ); vertex_buffer_indices[vertex_buffer].number = base_index - vertex_buffer_indices[vertex_buffer].base_index; if ( base_index ) { int count; // // Flush any buffered primitives // finalise_primitives (); // // Set the alpha blend modes // set_d3d_alpha_fog_zbuffer ( TRUE, FALSE, TRUE, FALSE ); // // Set the texture handle // set_d3d_texture ( 0, load_hardware_texture_map ( terrain_buffered_polygons_texture ) ); // // Draw all the buffered vertex buffers // for ( count = 0; count <= vertex_buffer; count++ ) { #ifdef _WIN32 unsigned int d3drval; d3drval = IDirect3DDevice7_DrawIndexedPrimitiveVB ( d3d.device, D3DPT_TRIANGLELIST, d3d.alpha_vertex_buffer[count], 0, vertex_buffer_indices[count].number_of_vertices_buffered, &buffered_indices[ vertex_buffer_indices[count].base_index ], vertex_buffer_indices[count].number, ( unsigned long ) ( 0 ) ); if ( d3drval != DD_OK ) { debug_log ( "Unable to draw buffered triangles: %s", get_ddraw_error_message ( d3drval ) ); } #endif Transform(); glVertexPointer(3, GL_FLOAT, sizeof(D3DTLVERTEX), 0); glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(D3DTLVERTEX), (GLvoid *) offsetof(D3DTLVERTEX, r)); glTexCoordPointer(2, GL_FLOAT, sizeof(D3DTLVERTEX), (GLvoid *) offsetof(D3DTLVERTEX, tu)); glDrawElements(GL_TRIANGLES,vertex_buffer_indices[count].number,GL_UNSIGNED_SHORT, (GLvoid *) buffered_indices[ vertex_buffer_indices[count].base_index]); // OpenGlDrawIndexedBuffer(GL_TRIANGLES,d3d.alpha_vertex_buffer[count],0,vertex_buffer_indices[count].number_of_vertices_buffered, // buffered_indices[ vertex_buffer_indices[count].base_index]); } // // Turn the blend mode off // set_d3d_alpha_fog_zbuffer ( FALSE, TRUE, TRUE, TRUE ); } // // Reset the things! // reset_terrain_3d_buffered_polygons (); } }
void create_texture_screen_data ( screen *texture, int width, int height, int type, int number_of_mipmaps, int renderto ) { DDSURFACEDESC2 ddsd; unsigned int ret; debug_log ( "Creating user texture screen: %d, %d ( %d mipmaps ) ( %d render to ) ", width, height, number_of_mipmaps, renderto ); #ifdef _WIN32 memset ( &ddsd, 0, sizeof ( ddsd ) ); ddsd.dwSize = sizeof ( ddsd ); // // Allocate a d3d managed texture // memcpy ( &ddsd.ddpfPixelFormat, &texture_formats[type].format, sizeof ( DDPIXELFORMAT ) ); ddsd.dwMipMapCount = 0; ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT; ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE; ddsd.dwHeight = height; ddsd.dwWidth = width; ddsd.ddsCaps.dwCaps3 = 0; ddsd.ddsCaps.dwCaps4 = 0; ddsd.ddsCaps.dwCaps2 = DDSCAPS2_HINTDYNAMIC | DDSCAPS2_TEXTUREMANAGE; if ( ( d3d_mipmap_textures ) && ( number_of_mipmaps > 1 ) ) { ddsd.dwFlags |= DDSD_MIPMAPCOUNT; ddsd.ddsCaps.dwCaps |= DDSCAPS_COMPLEX | DDSCAPS_MIPMAP; ddsd.dwMipMapCount = number_of_mipmaps; } ret = IDirectDraw7_CreateSurface ( ddraw.ddraw, &ddsd, &texture->surface, NULL ); if ( ret != DD_OK ) { debug_fatal ( "Unable to create texture surface: %s ( %d, %d )", get_ddraw_error_message ( ret ), width, height ); } #endif texture->surface = SDL_CreateRGBSurface(0,width,height,texture_formats[type].format.BitsPerPixel,texture_formats[type].format.Rmask, texture_formats[type].format.Gmask,texture_formats[type].format.Bmask,texture_formats[type].format.Amask); glGenTextures(1, &texture->texName); glBindTexture(GL_TEXTURE_2D, texture->texName); // // Texture doesn't have a colour table // texture->type = type; texture->palette = NULL; texture->colour_table = NULL; texture->pixel_length = texture_formats[type].bpp_red + texture_formats[type].bpp_green + texture_formats[type].bpp_blue + texture_formats[type].bpp_alpha; texture->clone_screen = FALSE; texture->do_not_destroy = FALSE; // // Setup render surface // if ( renderto ) { #ifdef _WIN32 memset ( &ddsd, 0, sizeof ( ddsd ) ); ddsd.dwSize = sizeof ( ddsd ); memcpy ( &ddsd.ddpfPixelFormat, &texture_formats[type].format, sizeof ( DDPIXELFORMAT ) ); ddsd.dwSize = sizeof ( ddsd ); ddsd.dwMipMapCount = 0; ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT; ddsd.ddsCaps.dwCaps = DDSCAPS_3DDEVICE; ddsd.dwHeight = height; ddsd.dwWidth = width; ddsd.ddsCaps.dwCaps3 = 0; ddsd.ddsCaps.dwCaps4 = 0; ddsd.ddsCaps.dwCaps2 = 0; ddsd.ddsCaps.dwCaps |= ( d3d_use_rgb_device ) ? ( DDSCAPS_SYSTEMMEMORY ) : ( DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM ); ret = IDirectDraw7_CreateSurface ( ddraw.ddraw, &ddsd, &texture->render_texture_surface, NULL ); if ( ret != DD_OK ) { debug_fatal ( "Unable to create texture render surface: %s ( %d, %d )", get_ddraw_error_message ( ret ), width, height ); } memset ( &ddsd, 0, sizeof ( ddsd ) ); ddsd.dwSize = sizeof ( ddsd ); ret = IDirectDrawSurface7_GetSurfaceDesc ( ddraw.lpFrontBuffer, &ddsd ); ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT; ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER; ddsd.ddsCaps.dwCaps |= ( d3d_use_rgb_device ) ? ( DDSCAPS_SYSTEMMEMORY ) : ( DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM ); ddsd.dwWidth = width; ddsd.dwHeight = height; #endif get_ddraw_zbuffer_pixel_format ( &ddsd.ddpfPixelFormat ); // ddsd.ddpfPixelFormat.dwSize = sizeof ( ddsd.ddpfPixelFormat ); // ddsd.ddpfPixelFormat.dwFlags = DDPF_ZBUFFER; // ddsd.ddpfPixelFormat.dwZBufferBitDepth = 16; #ifdef _WIN32 ret = IDirectDraw7_CreateSurface ( ddraw.ddraw, &ddsd, &texture->zbuffer_surface, NULL ); if ( ret != DD_OK ) { debug_fatal ( "Unable to create Zbuffer surface: %s", get_ddraw_error_message ( ret ) ); } ret = IDirectDrawSurface7_AddAttachedSurface ( texture->render_texture_surface, texture->zbuffer_surface ); if ( ret != DD_OK ) { debug_fatal ( "Unable to attach Zbuffer surface: %s", get_ddraw_error_message ( ret ) ); } #endif } }
int test_video_resolution ( int width, int height, int depth ) { unsigned int ddrval; DDSURFACEDESC2 ddsd; DDSCAPS2 caps; // // Set the video mode // { int parms[3]; parms[0] = width; parms[1] = height; parms[2] = depth; ddrval = system_thread_function ( ddraw_internal_set_display_mode, parms ); } if ( ddrval != DD_OK ) { debug_log ( "Unable to set display resolution: %d, %d, %d: %s", width, height, depth, get_ddraw_error_message ( ddrval ) ); return ( FALSE ); } // // Release any previous pointers // release_ddraw_surface_pointers (); // // Create the primary surface // memset ( &ddsd, 0, sizeof ( ddsd ) ); ddsd.dwSize = sizeof (ddsd); ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE; if ( ddraw.use_double_buffer ) { ddsd.dwFlags |= DDSD_BACKBUFFERCOUNT; ddsd.dwBackBufferCount = 1; ddsd.ddsCaps.dwCaps |= DDSCAPS_FLIP | DDSCAPS_COMPLEX; } #ifdef _WIN32 ddrval = IDirectDraw7_CreateSurface ( ddraw.ddraw, &ddsd, &ddraw.lpFrontBuffer, NULL); if ( ddrval != DD_OK ) { debug_log ( "Unable to create primary surface: %s", get_ddraw_error_message ( ddrval ) ); return ( FALSE ); } #endif if ( ddraw.use_double_buffer ) { // // Get the back screen from this surface. // memset ( &caps, 0, sizeof ( caps ) ); caps.dwCaps = DDSCAPS_BACKBUFFER; #ifdef _WIN32 ddrval = IDirectDrawSurface7_GetAttachedSurface ( ddraw.lpFrontBuffer, &caps, &ddraw.lpBackBuffer ); if ( ddrval != DD_OK ) { debug_log ( "Unable to get backbuffer: %s", get_ddraw_error_message ( ddrval ) ); return ( FALSE ); } #endif } if ( ddraw.use_system_memory ) { // // Create the system memory surface // memset ( &ddsd, 0, sizeof ( ddsd ) ); ddsd.dwSize = sizeof( ddsd ); #ifdef _WIN32 ddrval = IDirectDrawSurface7_GetSurfaceDesc ( ddraw.lpFrontBuffer, &ddsd ); #endif ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_SYSTEMMEMORY; ddsd.dwHeight = height; ddsd.dwWidth = width; #ifdef _WIN32 ddrval = IDirectDraw7_CreateSurface ( ddraw.ddraw , &ddsd, &ddraw.lpRenderBuffer, NULL ); if ( ddrval != DD_OK ) { debug_log ( "Unable to create system memory surface: %s", get_ddraw_error_message ( ddrval ) ); return ( FALSE ); } #endif } else { // // Set the render buffer // if ( ddraw.use_double_buffer ) { ddraw.lpRenderBuffer = ddraw.lpBackBuffer; ddraw.lpRenderBuffer = ddraw.lpBackBuffer; } else { ddraw.lpRenderBuffer = ddraw.lpFrontBuffer; ddraw.lpRenderBuffer = ddraw.lpFrontBuffer; } } if ( ddraw.use_z_buffer ) { // // Create the zbuffer and attach it to the render buffer. // memset ( &ddsd, 0, sizeof ( ddsd ) ); ddsd.dwSize = sizeof ( ddsd ); #ifdef _WIN32 ddrval = IDirectDrawSurface7_GetSurfaceDesc ( ddraw.lpFrontBuffer, &ddsd ); #endif ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT; ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY; ddsd.dwHeight = height; ddsd.dwWidth = width; get_ddraw_zbuffer_pixel_format ( &ddsd.ddpfPixelFormat ); #ifdef _WIN32 ddrval = IDirectDraw7_CreateSurface ( ddraw.ddraw, &ddsd, &ddraw.lpZBuffer, NULL ); if ( ddrval != DD_OK ) { debug_log ( "Unable to create Zbuffer surface: %s", get_ddraw_error_message ( ddrval ) ); return ( FALSE ); } ddrval = IDirectDrawSurface7_AddAttachedSurface ( ddraw.lpRenderBuffer, ddraw.lpZBuffer ); if ( ddrval != DD_OK ) { debug_log ( "Unable to attach Zbuffer surface: %s", get_ddraw_error_message ( ddrval ) ); return ( FALSE ); } #endif } application_video_width = width; application_video_height = height; return ( TRUE ); }