コード例 #1
0
ファイル: vid_win.c プロジェクト: quizzicol/myQuake
void VID_Update(void)
{
	
	DrawPic32(10, 10, 48, 56, CharData+8);

	HDC dc = GetDC(MainWindow);										// device context for the client space (the canvas) of the window
	StretchDIBits(dc,
		0, 0, WindowWidth, WindowHeight,							// window coordinates
		0, 0, Vid.BufferWidth, Vid.BufferHeight,							// source coordinate (same)
		(void *)Vid.BackBuffer, (BITMAPINFO*)&BitMapInfo,
		DIB_RGB_COLORS, SRCCOPY);

	ReleaseDC(MainWindow, dc);
}
コード例 #2
0
ファイル: sys_win.c プロジェクト: intothevoid/qfs
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    // define our window class
    WNDCLASSEX wc = { 0 };
    wc.cbSize = sizeof(wc);
    wc.lpfnWndProc = WindowProc;
    wc.hInstance = hInstance;
    wc.lpszClassName = "Module 3";

    RegisterClassExA(&wc);

    DWORD dwExStyle = 0;
    DWORD dwStyle = WS_OVERLAPPEDWINDOW;

    //BOOL Fullscreen = FALSE;
    //
    //if (Fullscreen)
    //{
    //    DEVMODE dmScreenSettings = { 0 };
    //    dmScreenSettings.dmSize = sizeof(dmScreenSettings);
    //    dmScreenSettings.dmPelsWidth = BufferWidth;
    //    dmScreenSettings.dmPelsHeight = BufferHeight;
    //    dmScreenSettings.dmBitsPerPel = 32;
    //    dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
    //
    //    if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) == //DISP_CHANGE_SUCCESSFUL)
    //    {
    //        dwExStyle = WS_EX_APPWINDOW;
    //        dwStyle = WS_POPUP;
    //    }
    //    else
    //    {
    //        Fullscreen = FALSE;
    //    }
    //}

    // create rectangle for window
    RECT r = { 0 };
    r.right = WindowWidth;
    r.bottom = WindowHeight;
    AdjustWindowRectEx(&r, dwStyle, 0, dwExStyle);

    // create our window
    HWND MainWindow = CreateWindowEx(
        dwExStyle, "Module 3",
        "Lesson 3.5", dwStyle,
        CW_USEDEFAULT, CW_USEDEFAULT,
        r.right - r.left, r.bottom - r.top,
        NULL, NULL,
        hInstance, 0);

    //if (Fullscreen)
    //    SetWindowLong(MainWindow, GWL_STYLE, 0);

    ShowWindow(MainWindow, nShowCmd);

    // define our bitmap info
    BitMapInfo.bmiHeader.biSize = sizeof(BitMapInfo.bmiHeader);
    BitMapInfo.bmiHeader.biWidth = BufferWidth;
    BitMapInfo.bmiHeader.biHeight = -BufferHeight;
    BitMapInfo.bmiHeader.biPlanes = 1;
    BitMapInfo.bmiHeader.biBitCount = 8 * BytesPerPixel;
    BitMapInfo.bmiHeader.biCompression = BI_RGB;

    BackBuffer = malloc(BufferWidth * BufferHeight * BytesPerPixel);

    //if (BytesPerPixel == 1)
    {
        FILE *Palette = fopen("palette.lmp", "rb");
        void *RawData = malloc(256 * 3);
        unsigned char* PaletteData = RawData;
        size_t Ret = fread(PaletteData, 1, 768, Palette);

        for (int i = 0; i < 256; i++)
        {
            BitMapInfo.acolors[i].rgbRed = *PaletteData++;
            BitMapInfo.acolors[i].rgbGreen = *PaletteData++;
            BitMapInfo.acolors[i].rgbBlue = *PaletteData++;
        }

        free(RawData);
        fclose(Palette);
    }

    FILE * Disc = fopen("DISC.lmp", "rb");
    int DiscWidth, DiscHeight;

    size_t RetVal = fread(&DiscWidth, 1, 4, Disc);
    RetVal = fread(&DiscHeight, 1, 4, Disc);
    void* DiscData = malloc(DiscWidth * DiscHeight);
    RetVal = fread(DiscData, 1, DiscWidth * DiscHeight, Disc);

    fclose(Disc);

    FILE *Pause = fopen("pause.lmp", "rb");
    int PauseWidth, PauseHeight;

    RetVal = fread(&PauseWidth, 1, 4, Pause);
    RetVal = fread(&PauseHeight, 1, 4, Pause);
    void *PauseData = malloc(PauseWidth * PauseHeight);
    RetVal = fread(PauseData, 1, PauseWidth * PauseHeight, Pause);

    fclose(Pause);
    MSG msg;
    while (Running)
    {
        while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }

        if (BytesPerPixel == 4)
        {
            int *MemoryWalker = (int*)BackBuffer;
            for (int Height = 0; Height < BufferHeight; Height++)
            {
                for (int Width = 0; Width < BufferWidth; Width++)
                {
                    unsigned char Red = rand() % 256;
                    unsigned char Green = rand() % 256;
                    unsigned char Blue = rand() % 256;

                    *MemoryWalker++ = ((Red << 16) | (Green << 8) | Blue);
                }
            }

            DrawPic32(10, 10, DiscWidth, DiscHeight, DiscData, BackBuffer);
            DrawPic32(100, 100, PauseWidth, PauseHeight, PauseData, BackBuffer);
            //DrawRect(10, 10, 300, 150, 255, 0, 255, BackBuffer);
        }
        else if (BytesPerPixel == 1)
        {
            unsigned char *MemoryWalker = BackBuffer;
            for (int Height = 0; Height < BufferHeight; Height++)
            {
                for (int Width = 0; Width < BufferWidth; Width++)
                {
                    *MemoryWalker++ = rand() % 256;
                }
            }

            //DrawPic8(10, 10, DiscWidth, DiscHeight, DiscData, BackBuffer);
            //DrawPic8(100, 100, PauseWidth, PauseHeight, PauseData, BackBuffer);
            //DrawRect8(10, 10, 300, 150, 1, BackBuffer);
        }
        HDC dc = GetDC(MainWindow);
        StretchDIBits(dc,
            0, 0, WindowWidth, WindowHeight,
            0, 0, BufferWidth, BufferHeight,
            BackBuffer, (BITMAPINFO*)&BitMapInfo,
            DIB_RGB_COLORS, SRCCOPY);
        ReleaseDC(MainWindow, dc);
    }

    free(BackBuffer);
    free(DiscData);
    free(PauseData);

    return EXIT_SUCCESS;
}