AP1994 Temat założony przez niniejszego użytkownika |
» 2025-01-26 16:04:47 niestety zarówno tekstura_przycisku1 =( HBITMAP ) LoadImage( GetModuleHandle( NULL ), MAKEINTRESOURCE( 3001 ), IMAGE_BITMAP,( Width / 2 ) * 0.1,( Height / 2 ) * 0.139, LR_CREATEDIBSECTION );
jak i tekstura_przycisku2 = LoadBitmap( hInstance, MAKEINTRESOURCE( 3002 ) );
nie działa sprawdziłem nawet na plikach bmp. tekstura_przycisku1 i tekstura_przycisku2 zwraca NULL #include "function.h" #include "resouces.h"
HBITMAP tekstura_przycisku1; HBITMAP tekstura_przycisku2; HBITMAP tekstura_przycisku3; HBITMAP tekstura_przycisku4; const int Width = GetSystemMetrics( SM_CXSCREEN ), Height = GetSystemMetrics( SM_CYSCREEN ); LRESULT CALLBACK WindowProc( HWND, UINT, WPARAM, LPARAM ); void EnableOpenGL( HWND hwnd, HDC *, HGLRC * ); void DisableOpenGL( HWND, HDC, HGLRC ); int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { tekstura_przycisku1 =( HBITMAP ) LoadImage( GetModuleHandle( NULL ), MAKEINTRESOURCE( 3001 ), IMAGE_BITMAP, ( Width / 2 ) * 0.1,( Height / 2 ) * 0.139, LR_CREATEDIBSECTION ); tekstura_przycisku2 = LoadBitmap( hInstance, MAKEINTRESOURCE( 3002 ) ); tekstura_przycisku3 = LoadBitmap( hInstance, MAKEINTRESOURCE( 3003 ) ); tekstura_przycisku4 = LoadBitmap( hInstance, MAKEINTRESOURCE( 3004 ) ); WNDCLASSEX wcex; HWND hwnd; HDC hDC; HGLRC hRC; MSG msg; BOOL bQuit = FALSE; HMENU hMenu = LoadMenu( hInstance, MAKEINTRESOURCE( 200 ) ); wcex.cbSize = sizeof( WNDCLASSEX ); wcex.style = CS_OWNDC; wcex.lpfnWndProc = WindowProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon( NULL, IDI_APPLICATION ); wcex.hCursor = LoadCursor( NULL, IDC_ARROW ); wcex.hbrBackground =( HBRUSH ) GetStockObject( BLACK_BRUSH ); wcex.lpszMenuName = NULL; wcex.lpszClassName = "GLSample"; wcex.hIconSm = LoadIcon( NULL, IDI_APPLICATION );; if( !RegisterClassEx( & wcex ) ) return 0; if( !al_init() ) { MessageBox( NULL, "Nie zainicjowano", "biblioteki allegro 5", MB_OK | MB_ICONERROR ); return 0; } al_init_font_addon(); if( !al_init_ttf_addon() ) { MessageBox( NULL, "Nie zainicjowano", "czcionki", MB_OK | MB_ICONERROR ); return 0; } if( !al_init_image_addon() ) { MessageBox( NULL, "Nie zainicjowano", "bitmap", MB_OK | MB_ICONERROR ); return - 1; } if( !al_init_primitives_addon() ) { MessageBox( NULL, "Nie zainicjowano", "prymitywów", MB_OK | MB_ICONERROR ); return - 1; } hwnd = CreateWindowEx( 0, "GLSample", "OpenGL Sample", WS_OVERLAPPED | WS_CAPTION | WS_BORDER | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, Width, Height, NULL, NULL, hInstance, NULL ); SetMenu( hwnd, hMenu ); ShowWindow( hwnd, nCmdShow ); EnableOpenGL( hwnd, & hDC, & hRC ); while( !bQuit ) { if( PeekMessage( & msg, NULL, 0, 0, PM_REMOVE ) ) { if( msg.message == WM_QUIT ) { bQuit = TRUE; } else { TranslateMessage( & msg ); DispatchMessage( & msg ); } } else { glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glOrtho( 0, Width, Height, 0, 0, 0 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); glClear( GL_COLOR_BUFFER_BIT ); glPushMatrix(); draw_filled_rectangle( 1, 1, - 1, 0.85, al_map_rgba_f( 0.75, 0.75, 0.75, 0.01 ) ); draw_filled_rectangle( 1, 1, 0.9, - 1, al_map_rgba_f( 0.75, 0.75, 0.75, 0.01 ) ); glPopMatrix(); SwapBuffers( hDC ); Sleep( 1 ); } } DisableOpenGL( hwnd, hDC, hRC ); DestroyWindow( hwnd ); return msg.wParam; }
LRESULT CALLBACK WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { static HWND hButton1; static HWND hButton2; static HWND hButton3; static HWND hButton4; switch( uMsg ) { case WM_CLOSE: PostQuitMessage( 0 ); break; case WM_CREATE: hButton1 = CreateWindow( "BUTTON", "", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_BITMAP, 1, 1, ( Width / 2 ) * 0.1,( Height / 2 ) * 0.139, hwnd, ( HMENU ) 1, ( HINSTANCE ) GetWindowLongPtr( hwnd, GWLP_HINSTANCE ), NULL ); if( !tekstura_przycisku1 ) { MessageBox( hwnd, "tekstura1!", "Informacja", MB_OK ); } SendMessage( hButton1, BM_SETIMAGE, IMAGE_BITMAP,( LPARAM ) tekstura_przycisku1 ); hButton2 = CreateWindow( "BUTTON", "", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_BITMAP, ( Width / 2 ) * 0.1, 1, ( Width / 2 ) * 0.1,( Height / 2 ) * 0.139, hwnd, ( HMENU ) 2, ( HINSTANCE ) GetWindowLongPtr( hwnd, GWLP_HINSTANCE ), NULL ); if( !tekstura_przycisku2 ) { MessageBox( hwnd, "tekstura2!", "Informacja", MB_OK ); } SendMessage( hButton2, BM_SETIMAGE, IMAGE_BITMAP,( LPARAM ) tekstura_przycisku2 ); hButton3 = CreateWindow( "BUTTON", "", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_BITMAP, ( Width / 2 ) * 0.2, 1, ( Width / 2 ) * 0.1,( Height / 2 ) * 0.139, hwnd, ( HMENU ) 3, ( HINSTANCE ) GetWindowLongPtr( hwnd, GWLP_HINSTANCE ), NULL ); SendMessage( hButton3, BM_SETIMAGE, IMAGE_BITMAP,( LPARAM ) tekstura_przycisku3 ); hButton4 = CreateWindow( "BUTTON", "", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_BITMAP, ( Width / 2 ) * 0.3, 1, ( Width / 2 ) * 0.1,( Height / 2 ) * 0.139, hwnd, ( HMENU ) 4, ( HINSTANCE ) GetWindowLongPtr( hwnd, GWLP_HINSTANCE ), NULL ); SendMessage( hButton4, BM_SETIMAGE, IMAGE_BITMAP,( LPARAM ) tekstura_przycisku4 ); break; case WM_DESTROY: return 0; case WM_COMMAND: switch( LOWORD( wParam ) ) { case 1: MessageBox( hwnd, "mysz!", "Informacja", MB_OK ); break; case 2: MessageBox( hwnd, "pozycja!", "Informacja", MB_OK ); break; case 3: MessageBox( hwnd, "skala!", "Informacja", MB_OK ); break; case 4: MessageBox( hwnd, "rotacja!", "Informacja", MB_OK ); break; case 100: MessageBox( hwnd, "Nowy plik", "Informacja", MB_OK ); break; case 101: MessageBox( hwnd, "Otwórz plik", "Informacja", MB_OK ); break; case 102: MessageBox( hwnd, "Zapisz plik", "Informacja", MB_OK ); break; } break; case WM_KEYDOWN: { if( wParam == VK_ESCAPE ) { PostQuitMessage( 0 ); } else if( wParam == 'W' ) { } else if( wParam == 'S' ) { } else if( wParam == 'A' ) { } else if( wParam == 'D' ) { } else if( wParam == 'R' ) { } } break; default: return DefWindowProc( hwnd, uMsg, wParam, lParam ); } return 0; }
void EnableOpenGL( HWND hwnd, HDC * hDC, HGLRC * hRC ) { PIXELFORMATDESCRIPTOR pfd; int iFormat; * hDC = GetDC( hwnd ); ZeroMemory( & pfd, sizeof( pfd ) ); pfd.nSize = sizeof( pfd ); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 32; pfd.cDepthBits = 16; pfd.iLayerType = PFD_MAIN_PLANE; iFormat = ChoosePixelFormat( * hDC, & pfd ); SetPixelFormat( * hDC, iFormat, & pfd ); * hRC = wglCreateContext( * hDC ); wglMakeCurrent( * hDC, * hRC ); }
void DisableOpenGL( HWND hwnd, HDC hDC, HGLRC hRC ) { wglMakeCurrent( NULL, NULL ); wglDeleteContext( hRC ); ReleaseDC( hwnd, hDC ); }
|