int main(void) { fatInitDefault(); #ifdef HAVE_FILE_LOGGER g_extern.verbose = true; log_fp = fopen("sd:/ssnes-log.txt", "w"); #endif wii_video_init(); wii_input_init(); sgui_handle_t *sgui = sgui_init("sd:/", menu_framebuf, SGUI_WIDTH * sizeof(uint16_t), _binary_console_font_bmp_start, folder_cb, NULL); const char *rom_path; int ret = 0; while ((rom_path = get_rom_path(sgui)) && ret == 0) { g_console.initialize_rarch_enable = true; strlcpy(g_console.rom_path, rom_path, sizeof(g_console.rom_path)); rarch_startup(NULL); bool repeat = false; input_wii.poll(NULL); do{ repeat = rarch_main_iterate(); }while(repeat && !g_console.frame_advance_enable); } if(g_console.emulator_initialized) rarch_main_deinit(); wii_input_deinit(); wii_video_deinit(); #ifdef HAVE_FILE_LOGGER fclose(log_fp); #endif sgui_free(sgui); return ret; }
int main( void ) { HANDLE thread = 0; sgui_widget* text; sgui_window* wnd; sgui_init( ); /* create an ordinary window */ wnd = sgui_window_create( NULL, 200, 160, SGUI_FIXED_SIZE ); sgui_window_set_title( wnd, "Direct3D widget" ); sgui_window_move_center( wnd ); sgui_window_set_visible( wnd, SGUI_VISIBLE ); /* create widgets */ text = sgui_label_create( 20, 130, "D3D11 Drawing Thread" ); /* create sub-view widget. See gl2.c for further explanation */ subview = sgui_subview_create( wnd, 10, 10, 180, 120, SGUI_DIRECT3D_11, NULL ); /* add widgets to the window */ sgui_window_add_widget( wnd, text ); sgui_window_add_widget( wnd, subview ); /* create drawing thread */ thread = CreateThread( 0, 0, d3d11_drawing_thread, 0, 0, 0 ); /* main loop */ sgui_main_loop( ); /* wait for the thread to terminate */ running = 0; WaitForSingleObject( thread, INFINITE ); CloseHandle( thread ); /* clean up */ sgui_window_destroy( wnd ); sgui_widget_destroy( subview ); sgui_widget_destroy( text ); sgui_deinit( ); return 0; }
int main( void ) { sgui_window* wnd; sgui_widget* rb; sgui_widget* wb; sgui_widget* eb; sgui_init( ); /* create a window */ wnd = sgui_window_create( NULL, 320, 150, 0 ); sgui_window_set_title( wnd, "Clipboard" ); sgui_window_move_center( wnd ); sgui_window_set_visible( wnd, SGUI_VISIBLE ); /* create some widgets */ rb = sgui_button_create( 30, 30, 120, 30, "Read Clipboard", 0 ); wb = sgui_button_create( 30, 70, 120, 30, "Write Clipboard", 0 ); eb = sgui_edit_box_create( 160, 70, 120, 128 ); /* add widgets to the window */ sgui_window_add_widget( wnd, rb ); sgui_window_add_widget( wnd, wb ); sgui_window_add_widget( wnd, eb ); /* hook event callbacks */ sgui_event_connect( rb, SGUI_BUTTON_OUT_EVENT, read_clipboard, wnd, SGUI_VOID ); sgui_event_connect( wb, SGUI_BUTTON_OUT_EVENT, write_clipboard, wnd, SGUI_POINTER, eb ); /* main loop */ sgui_main_loop( ); /* clean up */ sgui_window_destroy( wnd ); sgui_widget_destroy( rb ); sgui_widget_destroy( wb ); sgui_widget_destroy( eb ); sgui_deinit( ); return 0; }
int main( void ) { FLOAT bg[4] = { 0.0f, 0.2f, 0.4f, 1.0f }; int r=0, g=0, b=0, dr=1, dg=0, db=0; D3D11_SUBRESOURCE_DATA InitData; sgui_window_description desc; ID3DBlob *vsblob, *psblob; sgui_d3d11_context* ctx; ID3D11VertexShader* vs; ID3D11PixelShader* ps; ID3D11InputLayout* il; D3D11_BUFFER_DESC bd; UINT stride, offset; ID3D11Buffer* vbo; sgui_window* wnd; sgui_init( ); /* create a window. See gl1.c for further explanation */ desc.parent = NULL; desc.share = NULL; desc.width = 300; desc.height = 300; desc.flags = SGUI_DOUBLEBUFFERED; desc.backend = SGUI_DIRECT3D_11; desc.bits_per_pixel = 32; desc.depth_bits = 16; desc.stencil_bits = 0; desc.samples = 4; wnd = sgui_window_create_desc( &desc ); if( !wnd ) { fprintf( stderr, "Could not create Direct3D 11 window!\n" ); return -1; } /* make the window visible and get the context */ sgui_window_set_title( wnd, "Direct3D 11 Sample" ); sgui_window_move_center( wnd ); sgui_window_set_visible( wnd, SGUI_VISIBLE ); sgui_window_set_vsync( wnd, 1 ); ctx = (sgui_d3d11_context*)sgui_window_get_context( wnd ); /* compile shaders, create shader objects */ D3DCompile( vsh, strlen(vsh), NULL, NULL, NULL, "main", "vs_4_0", 0, 0, &vsblob, NULL ); D3DCompile( psh, strlen(psh), NULL, NULL, NULL, "main", "ps_4_0", 0, 0, &psblob, NULL ); ID3D11Device_CreateVertexShader( ctx->dev, vsblob->lpVtbl->GetBufferPointer(vsblob), vsblob->lpVtbl->GetBufferSize(vsblob), NULL, &vs ); ID3D11Device_CreatePixelShader( ctx->dev, psblob->lpVtbl->GetBufferPointer(psblob), psblob->lpVtbl->GetBufferSize(psblob), NULL, &ps ); /* create an input layout */ ID3D11Device_CreateInputLayout( ctx->dev, layout, LAYOUTCOUNT, vsblob->lpVtbl->GetBufferPointer(vsblob), vsblob->lpVtbl->GetBufferSize(vsblob), &il ); /* create a vertex buffer */ memset( &bd, 0, sizeof(bd) ); bd.Usage = D3D11_USAGE_DEFAULT; bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; bd.ByteWidth = sizeof(vertices); memset( &InitData, 0, sizeof(InitData) ); InitData.pSysMem = vertices; ID3D11Device_CreateBuffer( ctx->dev, &bd, &InitData, &vbo ); /* configure input assembler */ ID3D11DeviceContext_IASetInputLayout( ctx->ctx, il ); stride = 3 * sizeof(float); offset = 0; ID3D11DeviceContext_IASetVertexBuffers( ctx->ctx, 0, 1, &vbo, &stride, &offset ); ID3D11DeviceContext_IASetPrimitiveTopology( ctx->ctx, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST ); /* set shaders */ ID3D11DeviceContext_VSSetShader( ctx->ctx, vs, NULL, 0 ); ID3D11DeviceContext_PSSetShader( ctx->ctx, ps, NULL, 0 ); /* main loop. See gl1.c for further explanation */ while( sgui_main_loop_step( ) ) { /* background color animation */ r += dr; g += dg; b += db; if( r==0xFF && dr>0 ) { dr= 0; dg=1; db=0; } if( g==0xFF && dg>0 ) { dr= 0; dg=0; db=1; } if( b==0xFF && db>0 ) { dr=-1; dg=0; db=0; } if( r==0 && dr<0 ) { dr=0; dg=-1; db= 0; } if( g==0 && dg<0 ) { dr=0; dg= 0; db=-1; } if( b==0 && db<0 ) { dr=1; dg= 0; db= 0; } bg[0] = ((float)r) / ((float)255.0f); bg[1] = ((float)g) / ((float)255.0f); bg[2] = ((float)b) / ((float)255.0f); /* draw scene */ ID3D11DeviceContext_ClearRenderTargetView( ctx->ctx, ctx->backbuffer, bg ); ID3D11DeviceContext_ClearDepthStencilView( ctx->ctx, ctx->dsv, D3D11_CLEAR_DEPTH, 1.0f, 0x00 ); ID3D11DeviceContext_Draw( ctx->ctx, 3, 0 ); /* swap front and back buffer */ sgui_window_swap_buffers( wnd ); } /* clean up */ ID3D11Buffer_Release( vbo ); ID3D11InputLayout_Release( il ); ID3D11VertexShader_Release( vs ); ID3D11PixelShader_Release( ps ); vsblob->lpVtbl->Release( vsblob ); psblob->lpVtbl->Release( psblob ); sgui_window_destroy( wnd ); sgui_deinit( ); return 0; }
int main( void ) { sgui_window* wnd; sgui_widget* button; sgui_widget* text; sgui_widget* gl_view; sgui_init( ); /* create a normal window and make it visible */ wnd = sgui_window_create( NULL, 200, 200, SGUI_FIXED_SIZE ); sgui_window_set_title( wnd, "OpenGL widget" ); sgui_window_move_center( wnd ); sgui_window_set_visible( wnd, SGUI_VISIBLE ); /* create some widgets */ text = sgui_label_create(10, 130, "OpenGL\302\256 subview widget"); button = sgui_button_create( 10, 155, 75, 30, "Refresh", 0 ); /* Create a sub view widget. The sub-view widget manages a sub-window. The first argument is the parent window. The second and third arguments are the position of the sub view widget (10,10), followed by the size of the sub-window (180x120). The sixth argument is the window backend to use (OpenGL compatibillity profile). The last argument would allow us to supply a supply a window description structure for more fine grained controll. We don't use this, so we set it to NULL. */ gl_view = sgui_subview_create( wnd, 10, 10, 180, 120, SGUI_OPENGL_COMPAT, NULL ); /* The sub-view widget has a callback that it calls when the window it manages wants to be redrawn. */ sgui_subview_set_draw_callback( gl_view, glview_on_draw ); /* The functon sgui_subview_refresh forces the window of the sub-view to redraw itself. */ sgui_event_connect( button, SGUI_BUTTON_OUT_EVENT, sgui_subview_refresh, gl_view, SGUI_VOID ); /* add widgets to the window */ sgui_window_add_widget( wnd, text ); sgui_window_add_widget( wnd, button ); sgui_window_add_widget( wnd, gl_view ); /* main loop */ sgui_main_loop( ); /* clean up */ sgui_window_destroy( wnd ); sgui_widget_destroy( gl_view ); sgui_widget_destroy( text ); sgui_widget_destroy( button ); sgui_deinit( ); return 0; }
int main( void ) { D3D11_SUBRESOURCE_DATA InitData; ID3DBlob *vsblob, *psblob; sgui_d3d11_context* ctx; sgui_window* subwindow; ID3D11VertexShader* vs; ID3D11PixelShader* ps; ID3D11InputLayout* il; D3D11_BUFFER_DESC bd; sgui_widget* subview; UINT stride, offset; sgui_widget* button; ID3D11Buffer* vbo; sgui_widget* text; sgui_window* wnd; srand( time(NULL) ); sgui_init( ); /* create an ordinary window */ wnd = sgui_window_create( NULL, 200, 200, SGUI_FIXED_SIZE ); sgui_window_set_title( wnd, "D3D11 widget" ); sgui_window_move_center( wnd ); sgui_window_set_visible( wnd, SGUI_VISIBLE ); /* create some widgets */ text = sgui_label_create( 40, 130, "Direct3D\302\256 widget" ); button = sgui_button_create( 10, 155, 75, 30, "Refresh", 0 ); /* create a subview widget. See gl2.c for further explanation */ subview = sgui_subview_create( wnd, 10, 10, 180, 120, SGUI_DIRECT3D_11, NULL ); subwindow = sgui_subview_get_window( subview ); ctx = (sgui_d3d11_context*)sgui_window_get_context( subwindow ); /* compile shaders, create shader objects */ D3DCompile( vsh, strlen(vsh), NULL, NULL, NULL, "main", "vs_4_0", 0, 0, &vsblob, NULL ); D3DCompile( psh, strlen(psh), NULL, NULL, NULL, "main", "ps_4_0", 0, 0, &psblob, NULL ); ID3D11Device_CreateVertexShader( ctx->dev, vsblob->lpVtbl->GetBufferPointer(vsblob), vsblob->lpVtbl->GetBufferSize(vsblob), NULL, &vs ); ID3D11Device_CreatePixelShader( ctx->dev, psblob->lpVtbl->GetBufferPointer(psblob), psblob->lpVtbl->GetBufferSize(psblob), NULL, &ps ); /* create an input layout */ ID3D11Device_CreateInputLayout( ctx->dev, layout, LAYOUTCOUNT, vsblob->lpVtbl->GetBufferPointer(vsblob), vsblob->lpVtbl->GetBufferSize(vsblob), &il ); /* create a vertex buffer */ memset( &bd, 0, sizeof(bd) ); bd.Usage = D3D11_USAGE_DEFAULT; bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; bd.ByteWidth = sizeof(vertices); memset( &InitData, 0, sizeof(InitData) ); InitData.pSysMem = vertices; ID3D11Device_CreateBuffer( ctx->dev, &bd, &InitData, &vbo ); /* configure input assembler */ ID3D11DeviceContext_IASetInputLayout( ctx->ctx, il ); stride = 3 * sizeof(float); offset = 0; ID3D11DeviceContext_IASetVertexBuffers( ctx->ctx, 0, 1, &vbo, &stride, &offset ); ID3D11DeviceContext_IASetPrimitiveTopology( ctx->ctx, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST ); /* set shaders */ ID3D11DeviceContext_VSSetShader( ctx->ctx, vs, NULL, 0 ); ID3D11DeviceContext_PSSetShader( ctx->ctx, ps, NULL, 0 ); /* hook callbacks. See gl2.c for further explanation */ sgui_subview_set_draw_callback( subview, d3dview_on_draw ); sgui_event_connect( button, SGUI_BUTTON_OUT_EVENT, sgui_subview_refresh, subview, SGUI_VOID ); /* add widgets to the window */ sgui_window_add_widget( wnd, text ); sgui_window_add_widget( wnd, button ); sgui_window_add_widget( wnd, subview ); /* main loop */ sgui_main_loop( ); /* clean up */ ID3D11Buffer_Release( vbo ); ID3D11InputLayout_Release( il ); ID3D11VertexShader_Release( vs ); ID3D11PixelShader_Release( ps ); vsblob->lpVtbl->Release( vsblob ); psblob->lpVtbl->Release( psblob ); sgui_window_destroy( wnd ); sgui_widget_destroy( subview ); sgui_widget_destroy( text ); sgui_widget_destroy( button ); sgui_deinit( ); return 0; }
int main( void ) { LPDIRECT3DVERTEXBUFFER9 v_buffer; sgui_window_description desc; IDirect3DTexture9* texture; sgui_d3d9_context* ctx; sgui_canvas* texcanvas; IDirect3DDevice9* dev; sgui_widget* check2; sgui_widget* check; sgui_widget* butt; sgui_window* wnd; float a=0.0f; VOID* pVoid; float m[16]; sgui_init( ); /*************************** create a window **************************/ desc.parent = NULL; desc.share = NULL; desc.width = 640; desc.height = 480; desc.flags = SGUI_FIXED_SIZE|SGUI_DOUBLEBUFFERED; desc.backend = SGUI_DIRECT3D_9; desc.bits_per_pixel = 32; desc.depth_bits = 16; desc.stencil_bits = 0; desc.samples = 0; wnd = sgui_window_create_desc( &desc ); sgui_window_set_title( wnd, "Direct3D 9 Texture Canvas" ); sgui_window_move_center( wnd ); sgui_window_set_visible( wnd, SGUI_VISIBLE ); sgui_window_set_vsync( wnd, 1 ); /************************ createtexture canvas ************************/ texcanvas = sgui_tex_canvas_create( wnd, sgui_window_get_context( wnd ), 128, 128 ); butt = sgui_button_create( 10, 10, 60, 25, "Button", 0 ); check = sgui_checkbox_create( 10, 40, "Direct3D" ); check2 = sgui_checkbox_create( 10, 65, "Texture" ); sgui_button_set_state( check, 1 ); sgui_button_set_state( check2, 1 ); sgui_widget_add_child( &texcanvas->root, butt ); sgui_widget_add_child( &texcanvas->root, check ); sgui_widget_add_child( &texcanvas->root, check2 ); /************** connect keyboard input to texture canvas **************/ sgui_event_connect( wnd, SGUI_KEY_PRESSED_EVENT, sgui_canvas_send_window_event, texcanvas, SGUI_FROM_EVENT, SGUI_EVENT ); sgui_event_connect( wnd, SGUI_KEY_RELEASED_EVENT, sgui_canvas_send_window_event, texcanvas, SGUI_FROM_EVENT, SGUI_EVENT ); sgui_event_connect( wnd, SGUI_CHAR_EVENT, sgui_canvas_send_window_event, texcanvas, SGUI_FROM_EVENT, SGUI_EVENT ); /*************************** Direct3D setup ***************************/ /* get the device context, set new present parameters */ ctx = (sgui_d3d9_context*)sgui_window_get_context( wnd ); dev = ctx->device; IDirect3DDevice9_Reset( dev, &ctx->present ); /* create a vertex buffer */ IDirect3DDevice9_CreateVertexBuffer( dev, sizeof(vertices), 0, CUSTOMFVF, D3DPOOL_MANAGED, &v_buffer, NULL ); /* load vertex data */ IDirect3DVertexBuffer9_Lock( v_buffer, 0, 0, (void**)&pVoid, 0 ); memcpy( pVoid, vertices, sizeof(vertices) ); IDirect3DVertexBuffer9_Unlock( v_buffer ); /* setup renderer state */ IDirect3DDevice9_SetRenderState( dev, D3DRS_CULLMODE, D3DCULL_NONE ); IDirect3DDevice9_SetRenderState( dev, D3DRS_LIGHTING, FALSE ); IDirect3DDevice9_SetRenderState( dev, D3DRS_ZENABLE, TRUE ); /* set up perspective projection matrix */ perspective( m, 45.0f, (float)desc.width/(float)desc.height, 0.1f, 100.0f ); IDirect3DDevice9_SetTransform( dev, D3DTS_PROJECTION, (D3DMATRIX*)m ); /* set up texturing, bind canvas texture to stage 0 */ texture = sgui_tex_canvas_get_texture( texcanvas ); IDirect3DDevice9_SetTexture( dev, 0, (IDirect3DBaseTexture9*)texture ); IDirect3DDevice9_SetTextureStageState( dev, 0, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA ); IDirect3DDevice9_SetTextureStageState( dev, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); IDirect3DDevice9_SetTextureStageState( dev, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); IDirect3DDevice9_SetTextureStageState( dev, 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE ); IDirect3DDevice9_SetSamplerState(dev,0,D3DSAMP_MINFILTER,D3DTEXF_LINEAR); IDirect3DDevice9_SetSamplerState(dev,0,D3DSAMP_MAGFILTER,D3DTEXF_LINEAR); /****************************** main loop *****************************/ while( sgui_main_loop_step( ) ) { /* redraw widgets in dirty areas */ sgui_canvas_redraw_widgets( texcanvas, 1 ); /* draw scene */ IDirect3DDevice9_Clear( dev, 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0, 1.0f, 0 ); IDirect3DDevice9_BeginScene( dev ); transform( m, a ); IDirect3DDevice9_SetTransform( dev, D3DTS_VIEW, (D3DMATRIX*)m ); a += 0.01f; IDirect3DDevice9_SetFVF( dev, CUSTOMFVF ); IDirect3DDevice9_SetStreamSource( dev, 0, v_buffer, 0, sizeof(CUSTOMVERTEX) ); IDirect3DDevice9_DrawPrimitive( dev, D3DPT_TRIANGLELIST, 0, 8 ); IDirect3DDevice9_EndScene( dev ); /* swap front and back buffer */ sgui_window_swap_buffers( wnd ); } /****************************** clean up ******************************/ sgui_canvas_destroy( texcanvas ); sgui_widget_destroy( check2 ); sgui_widget_destroy( check ); sgui_widget_destroy( butt ); IDirect3DVertexBuffer9_Release( v_buffer ); sgui_window_destroy( wnd ); sgui_deinit( ); return 0; }
int main( void ) { sgui_widget *butt, *check, *check2, *label; sgui_window_description desc; sgui_window* subwnd; sgui_window* subwnd2; sgui_context* ctx; sgui_window* wnd; int selection; puts( "Select rendering backend: " ); puts( " 1) OpenGL(R) old" ); puts( " 2) OpenGL(R) 3.0+ core" ); puts( " 3) Direct3D(R) 9" ); puts( " 4) Direct3D(R) 11" ); puts( "\n 0) quit\n" ); selection = 0; scanf( "%d", &selection ); switch( selection ) { case 1: selection = SGUI_OPENGL_COMPAT; break; case 2: selection = SGUI_OPENGL_CORE; break; case 3: selection = SGUI_DIRECT3D_9; break; case 4: selection = SGUI_DIRECT3D_11; break; default: return 0; } sgui_init( ); /* create a window */ memset( &desc, 0, sizeof(desc) ); desc.width = WIDTH; desc.height = HEIGHT; desc.flags = SGUI_FIXED_SIZE|SGUI_DOUBLEBUFFERED; desc.backend = selection; desc.bits_per_pixel = 32; desc.depth_bits = 16; wnd = sgui_window_create_desc( &desc ); sgui_window_set_title( wnd, "subwm" ); sgui_window_move_center( wnd ); sgui_window_set_visible( wnd, SGUI_VISIBLE ); sgui_window_make_current( wnd ); sgui_window_set_vsync( wnd, 1 ); ctx = sgui_window_get_context( wnd ); renderer_init( selection, ctx ); /* */ wm = sgui_ctx_wm_create( wnd ); sgui_window_set_userptr( wnd, wm ); sgui_window_on_event( wnd, (sgui_window_callback)sgui_ctx_wm_inject_event ); /* create some sub windows */ subwnd = sgui_ctx_wm_create_window( wm, 256, 128, 0 ); subwnd2 = sgui_ctx_wm_create_window( wm, 256, 128, 0 ); sgui_window_set_visible( subwnd, 1 ); sgui_window_set_visible( subwnd2, 1 ); sgui_window_move( subwnd2, 10, 10 ); sgui_window_set_title( subwnd, "Sub Window" ); sgui_window_set_title( subwnd2, "Another Window" ); /* create a few widgets */ butt = sgui_button_create( 10, 35, 60, 25, "Button", 0 ); check = sgui_checkbox_create( 10, 65, "OpenGL" ); check2 = sgui_checkbox_create( 10, 90, "Texture" ); label = sgui_label_create( 10, 35, "Hello, world!\n\n" "From a <b><i>sub</i></b> window." ); sgui_button_set_state( check, 1 ); sgui_button_set_state( check2, 1 ); /* add the widgets to the sub windows */ sgui_window_add_widget( subwnd, butt ); sgui_window_add_widget( subwnd, check ); sgui_window_add_widget( subwnd, check2 ); sgui_window_add_widget( subwnd2, label ); /* main loop */ while( sgui_main_loop_step( ) ) { renderer_draw( selection, ctx ); if( drawgui ) sgui_ctx_wm_draw_gui( wm ); sgui_window_swap_buffers( wnd ); } /* clean up */ sgui_window_destroy( subwnd ); sgui_window_destroy( subwnd2 ); sgui_widget_destroy( butt ); sgui_widget_destroy( check ); sgui_widget_destroy( check2 ); sgui_widget_destroy( label ); sgui_ctx_wm_destroy( wm ); sgui_window_release_current( wnd ); sgui_window_destroy( wnd ); sgui_deinit( ); return 0; }