コード例 #1
0
ファイル: platform.win.c プロジェクト: prideout/pez
void zepSwapBuffers()
{
    SwapBuffers(hDC);
}
コード例 #2
0
void screen_refresh() {
    window_set_caption(room_caption);
    enigma::update_mouse_variables();
    SwapBuffers(enigma::window_hDC);
}
コード例 #3
0
bool WebGraphicsContext3DDefaultImpl::readBackFramebuffer(unsigned char* pixels, size_t bufferSize)
{
    if (bufferSize != static_cast<size_t>(4 * width() * height()))
        return false;

    makeContextCurrent();

#ifdef RENDER_TO_DEBUGGING_WINDOW
    SwapBuffers(m_canvasDC);
#else
    // Earlier versions of this code used the GPU to flip the
    // framebuffer vertically before reading it back for compositing
    // via software. This code was quite complicated, used a lot of
    // GPU memory, and didn't provide an obvious speedup. Since this
    // vertical flip is only a temporary solution anyway until Chrome
    // is fully GPU composited, it wasn't worth the complexity.

    bool mustRestoreFBO;
    if (m_attributes.antialias) {
        glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_multisampleFBO);
        glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_fbo);
        glBlitFramebufferEXT(0, 0, m_cachedWidth, m_cachedHeight, 0, 0, m_cachedWidth, m_cachedHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR);
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
        mustRestoreFBO = true;
    } else {
        if (m_boundFBO != m_fbo) {
            mustRestoreFBO = true;
            glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
        }
    }

    GLint packAlignment = 4;
    bool mustRestorePackAlignment = false;
    glGetIntegerv(GL_PACK_ALIGNMENT, &packAlignment);
    if (packAlignment > 4) {
        glPixelStorei(GL_PACK_ALIGNMENT, 4);
        mustRestorePackAlignment = true;
    }

#if PLATFORM(SKIA)
    glReadPixels(0, 0, m_cachedWidth, m_cachedHeight, GL_BGRA, GL_UNSIGNED_BYTE, pixels);
#elif PLATFORM(CG)
    glReadPixels(0, 0, m_cachedWidth, m_cachedHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pixels);
#else
#error Must port to your platform
#endif

    if (mustRestorePackAlignment)
        glPixelStorei(GL_PACK_ALIGNMENT, packAlignment);

    if (mustRestoreFBO)
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_boundFBO);

#ifdef FLIP_FRAMEBUFFER_VERTICALLY
    if (pixels)
        flipVertically(pixels, m_cachedWidth, m_cachedHeight);
#endif

#endif // RENDER_TO_DEBUGGING_WINDOW
    return true;
}
コード例 #4
0
/* MapPreviewCanvas::draw
 * Draws the map
 *******************************************************************/
void MapPreviewCanvas::draw()
{
	// Setup colours
	wxColour wxc;
	wxc.Set(map_view_col_background);	rgba_t col_view_background(wxc.Red(), wxc.Green(), wxc.Blue(), 255);
	wxc.Set(map_view_col_line_1s);		rgba_t col_view_line_1s(wxc.Red(), wxc.Green(), wxc.Blue(), 255);
	wxc.Set(map_view_col_line_2s);		rgba_t col_view_line_2s(wxc.Red(), wxc.Green(), wxc.Blue(), 255);
	wxc.Set(map_view_col_line_special);	rgba_t col_view_line_special(wxc.Red(), wxc.Green(), wxc.Blue(), 255);
	wxc.Set(map_view_col_line_macro);	rgba_t col_view_line_macro(wxc.Red(), wxc.Green(), wxc.Blue(), 255);

	// Setup the viewport
	glViewport(0, 0, GetSize().x, GetSize().y);

	// Setup the screen projection
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, GetSize().x, 0, GetSize().y, -1, 1);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	// Clear
	glClearColor(((double)col_view_background.r)/255.f, ((double)col_view_background.g)/255.f,
	             ((double)col_view_background.b)/255.f, ((double)col_view_background.a)/255.f);
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	// Translate to inside of pixel (otherwise inaccuracies can occur on certain gl implementations)
	if (OpenGL::accuracyTweak())
		glTranslatef(0.375f, 0.375f, 0);

	// Zoom/offset to show full map
	showMap();

	// Translate to middle of canvas
	glTranslated(GetSize().x * 0.5, GetSize().y * 0.5, 0);

	// Zoom
	glScaled(zoom, zoom, 1);

	// Translate to offset
	glTranslated(-offset_x, -offset_y, 0);

	// Setup drawing
	glDisable(GL_TEXTURE_2D);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glLineWidth(1.5f);
	glEnable(GL_LINE_SMOOTH);

	// Draw lines
	for (unsigned a = 0; a < lines.size(); a++)
	{
		mep_line_t line = lines[a];

		// Check ends
		if (line.v1 >= verts.size() || line.v2 >= verts.size())
			continue;

		// Get vertices
		mep_vertex_t v1 = verts[lines[a].v1];
		mep_vertex_t v2 = verts[lines[a].v2];

		// Set colour
		if (line.special)
			OpenGL::setColour(col_view_line_special);
		else if (line.macro)
			OpenGL::setColour(col_view_line_macro);
		else if (line.twosided)
			OpenGL::setColour(col_view_line_2s);
		else
			OpenGL::setColour(col_view_line_1s);

		// Draw line
		glBegin(GL_LINES);
		glVertex2d(v1.x, v1.y);
		glVertex2d(v2.x, v2.y);
		glEnd();
	}

	glLineWidth(1.0f);
	glDisable(GL_LINE_SMOOTH);

	// Swap buffers (ie show what was drawn)
	SwapBuffers();
}
コード例 #5
0
// Program Entry (WinMain)
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    MSG msg;
    bool done = false;

    Selene::CApplication app;
    Selene::g_Params.m_pApp = &app;

    // entry
    Selene::Entry(app);

    // process command line arguments
    int cmdLineLength = strlen(lpCmdLine);
    int iArgC = 0;
    char** astrArgV = NULL;
    char* strCmdLine = NULL;
    if (cmdLineLength == 0)
    {
        iArgC = 0;
        astrArgV = new char*[1];
        astrArgV[0] = "";
        strCmdLine = new char[1];
        strCmdLine[0] = 0;
    }
    else
    {
        strCmdLine = new char[cmdLineLength + 1];
        strcpy_s(strCmdLine, cmdLineLength + 1, lpCmdLine);
        int iIndex = 0;
        char* strToken = NULL;
        char* strNextToken = NULL;
        strToken = strtok_s(strCmdLine, " ", &strNextToken);
        while (strToken != NULL)
        {
            iIndex++;
            strToken = strtok_s(NULL, " ", &strNextToken);
        }
        iArgC = iIndex;
        astrArgV = new char*[iArgC];
        strcpy_s(strCmdLine, cmdLineLength + 1, lpCmdLine);
        strNextToken = NULL;
        strToken = strtok_s(strCmdLine, " ", &strNextToken);
        iIndex = 0;
        while (strToken != NULL)
        {
            astrArgV[iIndex] = strToken;
            iIndex++;
            strToken = strtok_s(NULL, " ", &strNextToken);
        }
    }
    app.ParseCommandLine(iArgC, astrArgV);
    SAFE_DELETE_ARRAY(astrArgV);
    SAFE_DELETE_ARRAY(strCmdLine);

    Selene::CAppConfig* pAppConfig = app.GetAppConfig();
    if (!Selene::CreateGLWindow(pAppConfig->GetAppName(),
                                pAppConfig->GetWindowWidth(),
                                pAppConfig->GetWindowHeight(),
                                32,
                                pAppConfig->GetFullscreen()))
    {
        return 0;
    }

    app.Init();

    while (!done)
    {
        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            if (msg.message == WM_QUIT)
            {
                done = true;
            }
            else
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }
        else
        {
            if (Selene::g_Params.m_Active)
            {
                if (app.ShouldQuit())
                {
                    done = true;
                }
                else
                {
                    app.Loop();
                    SwapBuffers(Selene::g_Params.m_DC);
                }
            }
        }
    }

    app.Terminate();

    Selene::KillGLWindow();
    return 0;
}
コード例 #6
0
ファイル: OpenGLSample.cpp プロジェクト: CmPons/angel2d
int main()
{

	//
	// Create a new window
	//
	g_pHWND = CreateGameWindow();

	//
	// Create OpenGL Device
	//
	HGLRC OpenGLContext = CreateOpenGLDeviceContext();	


	//
	// Create a GWEN OpenGL Renderer
	//
	#ifdef USE_DEBUG_FONT
		Gwen::Renderer::OpenGL * pRenderer = new Gwen::Renderer::OpenGL_DebugFont();
	#else
		Gwen::Renderer::OpenGL * pRenderer = new Gwen::Renderer::OpenGL();
	#endif

		pRenderer->Init();

	//
	// Create a GWEN skin
	//
	Gwen::Skin::TexturedBase skin( pRenderer );
	skin.Init("DefaultSkin.png");

	//
	// Create a Canvas (it's root, on which all other GWEN panels are created)
	//
	Gwen::Controls::Canvas* pCanvas = new Gwen::Controls::Canvas( &skin );
	pCanvas->SetSize( 998, 650 - 24 );
	pCanvas->SetDrawBackground( true );
	pCanvas->SetBackgroundColor( Gwen::Color( 150, 170, 170, 255 ) );

	//
	// Create our unittest control (which is a Window with controls in it)
	//
	UnitTest* pUnit = new UnitTest( pCanvas );
	pUnit->SetPos( 10, 10 );

	//
	// Create a Windows Control helper 
	// (Processes Windows MSG's and fires input at GWEN)
	//
	Gwen::Input::Windows GwenInput;
	GwenInput.Initialize( pCanvas );

	//
	// Begin the main game loop
	//
	MSG msg;
	while( true )
	{
		// Skip out if the window is closed
		if ( !IsWindowVisible( g_pHWND ) )
			break;

		// If we have a message from windows..
		if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
		{
			// .. give it to the input handler to process
			GwenInput.ProcessMessage( msg );

			// if it's QUIT then quit..
			if ( msg.message == WM_QUIT )
				break;


			// Handle the regular window stuff..
			TranslateMessage(&msg);
			DispatchMessage(&msg);

		}

		// Main OpenGL Render Loop
		{
			glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

			pCanvas->RenderCanvas();

			SwapBuffers( GetDC( g_pHWND ) );
		}
	}

	// Clean up OpenGL
	wglMakeCurrent( NULL, NULL );
	wglDeleteContext( OpenGLContext );

	delete pCanvas;
	delete pRenderer;

}
コード例 #7
0
ファイル: platform_win32.c プロジェクト: pqp/c8
int 
WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
     MSG msg = {0};
     WNDCLASS wc = {0};
     RECT wr;
     unsigned threadNum;

     wr.left   = 0;
     wr.right  = VIEW_WIDTH;
     wr.top    = 0;
     wr.bottom = VIEW_HEIGHT;

     wc.lpfnWndProc = WndProc;
     wc.hInstance   = hInstance;
     wc.lpszClassName = "C8WinClass";

     if (!RegisterClass(&wc))
          return 0;

     AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE);

     long style = WS_OVERLAPPEDWINDOW | WS_VISIBLE;
     /*
     style ^= WS_THICKFRAME;
     style ^= WS_MAXIMIZEBOX;
     */

     CreateWindow(wc.lpszClassName, "C8", style, 0, 0, (SCREEN_WIDTH * 4)+30, (SCREEN_HEIGHT * 4) + 30,
                  0, 0, hInstance, 0);

     freopen("stdout.txt", "w", stdout);
     freopen("stderr.txt", "w", stderr);

     if (!CHIP8_Init(lpCmdLine)) {
          running = false;
          return;
     }

     CHIP8_Reset();

     InitKeymap();

     _beginthread(InterpreterThread, 0, NULL);

     // TODO: formatting?
     while (running)
     {
          PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
          TranslateMessage(&msg);
          DispatchMessage(&msg);

          glClear(GL_COLOR_BUFFER_BIT);

          UpdateDisplay();

          SwapBuffers(dc);
     }

     return 0;
}
コード例 #8
0
void OpenGLWindow::swapBuffers()
{
	SwapBuffers(m_WindowDeviceContext);
}
コード例 #9
0
ファイル: fg_display_mswin.c プロジェクト: Galleondragon/qb64
void fgPlatformGlutSwapBuffers( SFG_PlatformDisplay *pDisplayPtr, SFG_Window* CurrentWindow )
{
    SwapBuffers( CurrentWindow->Window.pContext.Device );
}
コード例 #10
0
ファイル: main.cpp プロジェクト: elf11/newRepo
// Program Entry (WinMain)
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	Application			application;									// Application Structure
	GL_Window			window;											// Window Structure
//	Keys				keys;											// Key Structure
	BOOL				isMessagePumpActive;							// Message Pump Active?
	MSG					msg;											// Window Message Structure
	DWORD				tickCount;										// Used For The Tick Counter


	// Fill Out Application Data
	application.className = "OpenGL";									// Application Class Name
	application.hInstance = hInstance;									// Application Instance

	
	// Fill Out Window
	ZeroMemory (&window, sizeof (GL_Window));							// Make Sure Memory Is Zeroed
//	window.keys					= &keys;								// Window Key Structure
	window.init.application		= &application;							// Window Application
	window.init.title			= "Sky Gamblers: Jet Arena";			// Window Title
	window.init.width			= 1024;									// Window Width
	window.init.height			= 768;									// Window Height
	window.init.bitsPerPixel	= 32;									// Bits Per Pixel
	window.init.isFullScreen	= TRUE;									// Fullscreen? (Set To TRUE)

//	ZeroMemory (&keys, sizeof (Keys));									// Zero keys Structure

	// Ask The User If They Want To Start In FullScreen Mode?
	if (true)//MessageBox (HWND_DESKTOP, "Would You Like To Run In Fullscreen Mode?", "Start FullScreen?", MB_YESNO | MB_ICONQUESTION) == IDNO)
	{
		window.init.isFullScreen = FALSE;								// If Not, Run In Windowed Mode
	}

	// Register A Class For Our Window To Use
	if (RegisterWindowClass (&application) == FALSE)					// Did Registering A Class Fail?
	{
		// Failure
		MessageBox (HWND_DESKTOP, "Error Registering Window Class!", "Error", MB_OK | MB_ICONEXCLAMATION);
		return -1;														// Terminate Application
	}

	g_isProgramLooping = TRUE;											// Program Looping Is Set To TRUE
	g_createFullScreen = window.init.isFullScreen;						// g_createFullScreen Is Set To User Default
	while (g_isProgramLooping)											// Loop Until WM_QUIT Is Received
	{
		// Create A Window
		window.init.isFullScreen = g_createFullScreen;					// Set Init Param Of Window Creation To Fullscreen?
		if (CreateWindowGL (&window) == TRUE)							// Was Window Creation Successful?
		{
			// At This Point We Should Have A Window That Is Setup To Render OpenGL
			if (false)//Initialize (&window, &keys) == FALSE)					// Call User Intialization
			{
				// Failure
				TerminateApplication(&window);							// Close Window, This Will Handle The Shutdown
			}
			else														// Otherwise (Start The Message Pump)
			{	// Initialize was a success
				isMessagePumpActive = TRUE;								// Set isMessagePumpActive To TRUE


				TimerInit();

				init();
				//	return new RenderBuffer(0, frameBuffer, colorBuffer, 0, width, height, GL_COLOR_BUFFER_BIT, (void*) CreateScreenColor);

				while (isMessagePumpActive == TRUE)						// While The Message Pump Is Active
				{

				float start = GetTime();

					// Success Creating Window.  Check For Window Messages
					if (PeekMessage (&msg, window.hWnd, 0, 0, PM_REMOVE) != 0)
					{
						// Check For WM_QUIT Message
						if (msg.message != WM_QUIT)						// Is The Message A WM_QUIT Message?
						{
							DispatchMessage (&msg);						// If Not, Dispatch The Message
						}
						else											// Otherwise (If Message Is WM_QUIT)
						{
							isMessagePumpActive = FALSE;				// Terminate The Message Pump
						}
					}
					//else												// If There Are No Messages
					{
						if (window.isVisible == FALSE)					// If Window Is Not Visible
						{
							WaitMessage ();								// Application Is Minimized Wait For A Message
						}
						else											// If Window Is Visible
						{

							// Process Application Loop

							//draw
							display();

							SwapBuffers (window.hDC);					// Swap Buffers (Double Buffering)

							//update
							float end = GetTime();

							float _sleep_time = 1000.f/60.f - (end-start);
							// controlling framerate here
							if(_sleep_time>0){
							//	Sleep(_sleep_time);
							}						// Draw Our Scene

						}
					}

				}														// Loop While isMessagePumpActive == TRUE
			}															// If (Initialize (...

			// Application Is Finished

			DestroyWindowGL (&window);									// Destroy The Active Window
		}
		else															// If Window Creation Failed
		{
			// Error Creating Window
			MessageBox (HWND_DESKTOP, "Error Creating OpenGL Window", "Error", MB_OK | MB_ICONEXCLAMATION);
			g_isProgramLooping = FALSE;									// Terminate The Loop
		}
	}																	// While (isProgramLooping)

	UnregisterClass (application.className, application.hInstance);		// UnRegister Window Class
	return 0;
}																		// End Of WinMain()
コード例 #11
0
ファイル: gl_w32.c プロジェクト: Aseeker/mpv
static void swapGlBuffers_w32(MPGLContext *ctx)
{
    HDC vo_hdc = GetDC(ctx->vo->w32->window);
    SwapBuffers(vo_hdc);
    ReleaseDC(ctx->vo->w32->window, vo_hdc);
}
コード例 #12
0
ファイル: oglContext.cpp プロジェクト: byhj/byhj-Render
	void OGLContext::render()
	{
		SwapBuffers(hdc); // Swap buffers so we can see our rendering
	}
コード例 #13
0
ファイル: graphics_opengl_win32.c プロジェクト: 10n1/LAE
void lae_graphics_present(lae_graphics_t* device)
{
    SwapBuffers(device->dc);
    UNUSED_PARAMETER(device);
}
コード例 #14
0
ファイル: platform.win.c プロジェクト: prideout/pez
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE ignoreMe0, LPSTR ignoreMe1, INT ignoreMe2)
{
    LPCSTR szName = "Zep App";
    WNDCLASSEXA wc = { sizeof(WNDCLASSEX), CS_CLASSDC | CS_DBLCLKS, MsgProc, 0L, 0L, GetModuleHandle(0), 0, 0, 0, 0, szName, 0 };
    DWORD dwStyle = WS_SYSMENU | WS_VISIBLE | WS_POPUP;
    DWORD dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
    RECT rect;
    int windowWidth, windowHeight, windowLeft, windowTop;
    HWND hWnd;
    PIXELFORMATDESCRIPTOR pfd;
    HGLRC hRC;
    int pixelFormat;
    GLenum err;
    MSG msg = {0};
    LARGE_INTEGER previousTime;
    LARGE_INTEGER freqTime;

    wc.hCursor = LoadCursor(0, IDC_ARROW);
    RegisterClassExA(&wc);

    SetRect(&rect, 0, 0, ZepGetConfig().Width, ZepGetConfig().Height);
    AdjustWindowRectEx(&rect, dwStyle, FALSE, dwExStyle);
    windowWidth = rect.right - rect.left;
    windowHeight = rect.bottom - rect.top;
    windowLeft = GetSystemMetrics(SM_CXSCREEN) / 2 - windowWidth / 2;
    windowTop = GetSystemMetrics(SM_CYSCREEN) / 2 - windowHeight / 2;
    hWnd = CreateWindowExA(0, szName, szName, dwStyle, windowLeft, windowTop, windowWidth, windowHeight, 0, 0, 0, 0);

    // Create the GL context.
    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 = 24;
    pfd.cDepthBits = 0;
    pfd.cStencilBits = 0;
    pfd.iLayerType = PFD_MAIN_PLANE;

    hDC = GetDC(hWnd);
    pixelFormat = ChoosePixelFormat(hDC, &pfd);

    SetPixelFormat(hDC, pixelFormat, &pfd);
    hRC = wglCreateContext(hDC);
    wglMakeCurrent(hDC, hRC);

    if (ZepGetConfig().Multisampling)
    {
        int pixelAttribs[] =
        {
            WGL_SAMPLES_ARB, 16,
            WGL_SAMPLE_BUFFERS_ARB, GL_TRUE,
            WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
            WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
            WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
            WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
            WGL_RED_BITS_ARB, 8,
            WGL_GREEN_BITS_ARB, 8,
            WGL_BLUE_BITS_ARB, 8,
            WGL_ALPHA_BITS_ARB, 8,
            WGL_DEPTH_BITS_ARB, 24,
            WGL_STENCIL_BITS_ARB, 8,
            WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
            0
        };
        int* sampleCount = pixelAttribs + 1;
        int* useSampleBuffer = pixelAttribs + 3;
        int pixelFormat = -1;
        PROC proc = wglGetProcAddress("wglChoosePixelFormatARB");
        unsigned int numFormats;
        PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC) proc;

        if (!wglChoosePixelFormatARB)
        {
            zepFatal("Could not load function pointer for 'wglChoosePixelFormatARB'.  Is your driver properly installed?");
        }

        // Try fewer and fewer samples per pixel till we find one that is supported:
        while (pixelFormat <= 0 && *sampleCount >= 0)
        {
            wglChoosePixelFormatARB(hDC, pixelAttribs, 0, 1, &pixelFormat, &numFormats);
            (*sampleCount)--;
            if (*sampleCount <= 1)
            {
                *useSampleBuffer = GL_FALSE;
            }
        }

        // Win32 allows the pixel format to be set only once per app, so destroy and re-create the app:
        DestroyWindow(hWnd);
        hWnd = CreateWindowExA(0, szName, szName, dwStyle, windowLeft, windowTop, windowWidth, windowHeight, 0, 0, 0, 0);
        SetWindowPos(hWnd, HWND_TOP, windowLeft, windowTop, windowWidth, windowHeight, 0);
        hDC = GetDC(hWnd);
        SetPixelFormat(hDC, pixelFormat, &pfd);
        hRC = wglCreateContext(hDC);
        wglMakeCurrent(hDC, hRC);
    }

#ifdef ZEP_DROP_HANDLER
    DragAcceptFiles(hWnd, TRUE);
#endif

    err = glewInit();
    if (GLEW_OK != err)
    {
        zepFatal("GLEW Error: %s\n", glewGetErrorString(err));
    }
    zepPrintString("OpenGL Version: %s\n", glGetString(GL_VERSION));

    if (!ZepGetConfig().VerticalSync)
    {
        wglSwapIntervalEXT(0);
    }

    if (ZEP_FORWARD_COMPATIBLE_GL && glewIsSupported("GL_VERSION_3_2"))
    {
        const int contextAttribs[] =
        {
            WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
            WGL_CONTEXT_MINOR_VERSION_ARB, 2,
            WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
            0
        };

        HGLRC newRC = wglCreateContextAttribsARB(hDC, 0, contextAttribs);
        wglMakeCurrent(0, 0);
        wglDeleteContext(hRC);
        hRC = newRC;
        wglMakeCurrent(hDC, hRC);

        zepPrintString("Switched to a forward-compatible context.\n");
    }

    zepInit();
    zepAddPath("./", ".glsl");
    zepAddPath("../", ".glsl");

    char qualifiedPath[128];
    strcpy(qualifiedPath, zepResourcePath());
    strcat(qualifiedPath, "/");
    zepAddPath(qualifiedPath, ".glsl");

    zepAddDirective("*", "#version 150");

    ZepInitialize();
    SetWindowTextA(hWnd, ZepGetConfig().Title);

    QueryPerformanceFrequency(&freqTime);
    QueryPerformanceCounter(&previousTime);

    // -------------------
    // Start the Game Loop
    // -------------------
    while (msg.message != WM_QUIT)
    {
        if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else
        {
            LARGE_INTEGER currentTime;
            __int64 elapsed;
            double deltaTime;

            QueryPerformanceCounter(&currentTime);
            elapsed = currentTime.QuadPart - previousTime.QuadPart;
            deltaTime = elapsed * 1000000.0 / freqTime.QuadPart;
            previousTime = currentTime;

            ZepUpdate((float) deltaTime / 1000000.0f);
            ZepRender();
            SwapBuffers(hDC);
            zepCheck(glGetError() == GL_NO_ERROR, "OpenGL error.\n");
        }
    }

    UnregisterClassA(szName, wc.hInstance);

    return 0;
}
コード例 #15
0
ファイル: glctx-wgl.c プロジェクト: realh/glcontext
void glctx_flip(GlctxHandle ctx)
{
    SwapBuffers(ctx->dpy);
}
コード例 #16
0
ファイル: Win32Window.cpp プロジェクト: mrcrr8614/bullet3
void	Win32Window::endRendering()
{
	SwapBuffers( m_data->m_hDC );
}
コード例 #17
0
ファイル: SeasonalWindow.cpp プロジェクト: wrdn/SeasonalGlobe
// Display scene
void SeasonalWindow::OnDisplay()
{
	gameTime.Update();

	glDisable(GL_LIGHTING);
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_DEPTH_TEST);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
	glClearColor(0,0,0,1);

	// draw world
	scn.Draw(gameTime);

	glDisable(GL_DEPTH_TEST);

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();

	// draw current season
	glRasterPos2f(0.5f, 0.9f);
	Printf("Current Season: %s", scn.GetCurrentSeasonString());
	
	// draw current time multiplier
	glRasterPos2f(-0.96f, 0.9f);
	Printf("Current Time Multiplier: %f", scn.GetMultiplier());

	// display help menu if required
	if(displayHelpMenu)
	{
		glRasterPos2f(-0.96f, 0.75f); Printf("Press p to pause/ unpause time");
		glRasterPos2f(-0.96f, 0.7f);  Printf("Press +/- to increase/decrease time multiplier");

		glRasterPos2f(-0.96f, 0.6f);  Printf("Press s to switch lighting mode");
		glRasterPos2f(-0.96f, 0.55f); Printf("Press t to switch polygon mode (wireframe or fill)");
		glRasterPos2f(-0.96f, 0.5f);  Printf("Press m to switch tree viewing mode");

		glRasterPos2f(-0.96f, 0.4f);  Printf("Press Left/Right or Up/Down arrows to rotate camera");
		glRasterPos2f(-0.96f, 0.35f); Printf("Hold Left Mouse and move mouse to zoom");
		glRasterPos2f(-0.96f, 0.3f);  Printf("Hold Right Mouse and move mouse to rotate");

		glRasterPos2f(-0.96f, 0.2f);  Printf("Press h to hide/display this help menu");
	}
	else
	{
		glRasterPos2f(-0.96f, 0.80f);
		Printf("Press h to display help menu");
	}
	
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();   
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();

	glEnable(GL_DEPTH_TEST);

	SwapBuffers();
};
コード例 #18
0
ファイル: Lesson6.cpp プロジェクト: sunragav/LibGizmo
int WINAPI WinMain(	HINSTANCE	hInstance,			// Instance
					HINSTANCE	hPrevInstance,		// Previous Instance
					LPSTR		lpCmdLine,			// Command Line Parameters
					int			nCmdShow)			// Window Show State
{
	MSG		msg;									// Windows Message Structure
	BOOL	done=FALSE;								// Bool Variable To Exit Loop

	// Ask The User Which Screen Mode They Prefer
	MessageBox(NULL,"Press 1/2/3 to change gizmo.", "Manual",MB_OK);
	
	fullscreen = FALSE;							// Windowed Mode
	

	// Create Our OpenGL Window
	if (!CreateGLWindow("LibGizmo Test application Base on NeHe's Texture Mapping Tutorial",640,480,32,fullscreen))
	{
		return 0;									// Quit If Window Was Not Created
	}

	while(!done)									// Loop That Runs While done=FALSE
	{
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))	// Is There A Message Waiting?
		{
			if (msg.message==WM_QUIT)				// Have We Received A Quit Message?
			{
				done=TRUE;							// If So done=TRUE
			}
			else									// If Not, Deal With Window Messages
			{
				TranslateMessage(&msg);				// Translate The Message
				DispatchMessage(&msg);				// Dispatch The Message
			}
		}
		else										// If There Are No Messages
		{
			// Draw The Scene.  Watch For ESC Key And Quit Messages From DrawGLScene()
			if ((active && !DrawGLScene()) || keys[VK_ESCAPE])	// Active?  Was There A Quit Received?
			{
				done=TRUE;							// ESC or DrawGLScene Signalled A Quit
			}
			else									// Not Time To Quit, Update Screen
			{
				SwapBuffers(hDC);					// Swap Buffers (Double Buffering)
			}

			if (keys[VK_F1])						// Is F1 Being Pressed?
			{
				keys[VK_F1]=FALSE;					// If So Make Key FALSE
				KillGLWindow();						// Kill Our Current Window
				fullscreen=!fullscreen;				// Toggle Fullscreen / Windowed Mode
				// Recreate Our OpenGL Window
				if (!CreateGLWindow("LibGizmo Test application Base on NeHe's Texture Mapping Tutorial",640,480,16,fullscreen))
				{
					return 0;						// Quit If Window Was Not Created
				}
			}
		}
	}

	// Shutdown
	KillGLWindow();									// Kill The Window
	return (msg.wParam);							// Exit The Program
}
コード例 #19
0
/* BrowserCanvas::draw
 * Handles drawing of the canvas content
 *******************************************************************/
void BrowserCanvas::draw()
{
	// Setup the viewport
	glViewport(0, 0, GetSize().x, GetSize().y);

	// Setup the screen projection
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, GetSize().x, GetSize().y, 0, -1, 1);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	// Setup colours
	rgba_t col_bg, col_text;
	bool text_shadow = true;
	if (browser_bg_type == 1)
	{
		// Get system panel background colour
		wxColour bgcolwx = Drawing::getPanelBGColour();
		col_bg.set(bgcolwx.Red(), bgcolwx.Green(), bgcolwx.Blue());

		// Get system text colour
		wxColour textcol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
		col_text.set(textcol.Red(), textcol.Green(), textcol.Blue());

		// Check text colour brightness, if it's dark don't draw text shadow
		rgba_t col_temp = col_text;
		wxColor::MakeGrey(&col_temp.r, &col_temp.g, &col_temp.b);
		if (col_temp.r < 60)
			text_shadow = false;
	}
	else
	{
		// Otherwise use black background
		col_bg.set(0, 0, 0);

		// And white text
		col_text.set(255, 255, 255);
	}

	// Clear
	glClearColor(col_bg.fr(), col_bg.fg(), col_bg.fb(), 1.0f);
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	// Translate to inside of pixel (otherwise inaccuracies can occur on certain gl implementations)
	if (OpenGL::accuracyTweak())
		glTranslatef(0.375f, 0.375f, 0);

	// Draw background if required
	if (browser_bg_type == 0)
		drawCheckeredBackground();

	// Init for texture drawing
	glEnable(GL_TEXTURE_2D);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glLineWidth(2.0f);

	// Draw items
	int x = item_border;
	int y = item_border;
	int col_width = GetSize().x / num_cols;
	int col = 0;
	top_index = -1;
	for (unsigned a = 0; a < items_filter.size(); a++)
	{
		// If we're not yet into the viewable area, skip
		if (y < yoff - fullItemSizeY())
		{
			col++;
			if (col >= num_cols)
			{
				col = 0;
				y += fullItemSizeY();

				// Canvas is filled, stop drawing
				if (y > yoff + GetSize().y)
					break;
			}
			continue;
		}

		// If we're drawing the first non-hidden item, save it
		if (top_index < 0)
		{
			top_index = a;
			top_y = y - yoff;
		}

		// Determine current x position
		int xgap = (col_width - fullItemSizeX()) * 0.5;
		x = item_border + xgap + (col * col_width);

		// Draw selection box if selected
		if (item_selected == items[items_filter[a]])
		{
			// Setup
			glDisable(GL_TEXTURE_2D);
			glColor4f(0.3f, 0.5f, 1.0f, 0.3f);
			glPushMatrix();
			glTranslated(x, y - yoff, 0);
			glTranslated(-item_border, -item_border, 0);

			// Selection background
			glBegin(GL_QUADS);
			glVertex2i(2, 2);
			glVertex2i(2, fullItemSizeY()-3);
			glVertex2i(fullItemSizeX()-3, fullItemSizeY()-3);
			glVertex2i(fullItemSizeX()-3, 2);
			glEnd();

			// Selection border
			glColor4f(0.6f, 0.8f, 1.0f, 1.0f);
			glBegin(GL_LINE_LOOP);
			glVertex2i(2, 2);
			glVertex2i(2, fullItemSizeY()-3);
			glVertex2i(fullItemSizeX()-3, fullItemSizeY()-3);
			glVertex2i(fullItemSizeX()-3, 2);
			glEnd();

			// Finish
			glPopMatrix();
			glEnable(GL_TEXTURE_2D);
			glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
		}

		// Draw item
		if (item_size <= 0)
			items[items_filter[a]]->draw(browser_item_size, x, y - yoff, font, show_names, item_type, col_text, text_shadow);
		else
			items[items_filter[a]]->draw(item_size, x, y - yoff, font, show_names, item_type, col_text, text_shadow);

		// Move over for next item
		col++;
		if (col >= num_cols)
		{
			col = 0;
			y += fullItemSizeY();

			// Canvas is filled, stop drawing
			if (y > yoff + GetSize().y)
				break;
		}
	}

	// Swap Buffers
	SwapBuffers();
}
コード例 #20
0
ファイル: WglContext.cpp プロジェクト: MrShedman/GL-Dev
void WglContext::display()
{
    if (m_deviceContext && m_context)
        SwapBuffers(m_deviceContext);
}
コード例 #21
0
ファイル: RunGL.cpp プロジェクト: marcclintdion/iOS_WIN2
void RenderGL(void)
{
        
        //======================================================_SHADOWS_BEGIN_===========================================================================	                       
        //======================================================_SHADOWS_BEGIN_===========================================================================	                       
        //======================================================_SHADOWS_BEGIN_===========================================================================	                       
        //======================================================_SHADOWS_BEGIN_===========================================================================	                       
        
        //=============================================================================================================================  
        
        glBindFramebuffer(GL_FRAMEBUFFER, fboId_2D);//-----------------------F.B.O.     
        //----------------------------------------------------------------
        //glColor4f(color is changed using fragment program)
        glClearColor(1.0, 1.0, 1.0, 0.0);
        glClear (GL_COLOR_BUFFER_BIT);
        glViewport(0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT);
        //----------------------------------------------------------------
        
        glDisable(GL_BLEND);
        glDisable(GL_DEPTH_TEST);
        
        PerspectiveMatrix(ProjectionShadow, 45, 1.0, 0.001, 10000.0);
        
        Rotate(ProjectionShadow, 0.0, 1.0, 0.0, 20.0);
        Rotate(ProjectionShadow, 1.0, 0.0, 0.0, 45.0);
        
        glUseProgram(SHADER_shadow);//---------<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<  
        
        //############################################################################################################################################################|__SHADOW_01
        //============================================================================================================================================================|__LAYER__01
        glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_TRUE); 
        //===================================================== 
        darkness_shadow[0] = 0.5;
        darkness_shadow[1] = 0.5;
        darkness_shadow[2] = 0.5;
        
        //#include "_MODEL_FOLDERS_/flowerShield/flowerShield_Shadow_01.cpp"                                                              
        //====================================================================================                                          
        //#include "_MODEL_FOLDERS_/flowerShield/flowerShield_Shadow_00.cpp"                                                              

        //============================================================================================================================================================|__LAYER__02       
        glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_TRUE); 
        //===========================================================                     
        
        //---------------------------------------------------------                                  
       
        //############################################################################################################################################################|__SHADOW_02
        
        //============================================================================================================================================================|__LAYER__01
        glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_TRUE); 
        //===========================================================                       
        darkness_shadow[0] = 0.3;
        darkness_shadow[1] = 0.3;
        darkness_shadow[2] = 0.3;
        
        //============================================================================================================================================================|__LAYER__02     
        glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_TRUE); 
        //===========================================================
        
        //------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
        LoadIdentity(textureMatrix);
        AssignMatrix(textureMatrix, ProjectionShadow); 
        //===========================================================
        glEnable(GL_DEPTH_TEST);                                 
        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 	                       
        glBindFramebuffer(GL_FRAMEBUFFER, 0);	                       

        //======================================================_SHADOWS_END_=============================================================================	                       
        //======================================================_SHADOWS_END_=============================================================================	                       
        //======================================================_SHADOWS_END_=============================================================================	                       
        //======================================================_SHADOWS_END_=============================================================================	 

//##################################################################################################################################################################################################        
//##################################################################################################################################################################################################         
//##################################################################################################################################################################################################         
//##################################################################################################################################################################################################          
        
        //========================================================================================================================================================        
        //---------------------------------------------------RETURN_TO_MAIN_FRAMEBUFFER____________________!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        //---------------------------------------------------RETURN_TO_MAIN_FRAMEBUFFER____________________!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        //========================================================================================================================================================        
        #ifdef __APPLE__    
            glBindFramebuffer(GL_FRAMEBUFFER, msaaFramebuffer);
        #endif    
        //========================================================================================================================================================        
        //---------------------------------------------------RETURN_TO_MAIN_FRAMEBUFFER____________________!!!!!!!!!!!!!!!!!!!!!!!!!!!!        
        //---------------------------------------------------RETURN_TO_MAIN_FRAMEBUFFER____________________!!!!!!!!!!!!!!!!!!!!!!!!!!!!          
        //========================================================================================================================================================





        //=========================================================================================================================================================    
        glClearColor( 0.0f, 0.0f, 0.0f, 0.5f );
        glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); 
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
        //----------------------------------------------------------------------------------
        glViewport(0, 0, viewWidth, viewHeight);
        PerspectiveMatrix(projection, 45,(float)viewWidth / (float)viewHeight, 0.1, 10000);
        //=========================================================================================================================================================
        #ifdef __APPLE__
        Rotate(projection, 0.0, 0.0, 1.0, -90.0);//_____FOR_iOS_LANDSCAPE_VIEW 
        #endif        
        //=========================================================================================================================================================        
        projection[12] = eyePosition[1];
        projection[13] = eyePosition[0];
        projection[15] = eyePosition[2];
        Rotate(projection, 1.0, 0.0, 0.0,  look_UP_DOWN);
        Rotate(projection, 0.0, 1.0, 0.0, -look_LEFT_RIGHT);        
        
//#################################################################################################################################################################        
        


        //====================================================================================                                          
        #include "_MODEL_FOLDERS_/flowerShield/flowerShield_Render.cpp"                                                                 
        //====================================================================================                                          

  
  
                        
    
        
        #ifdef WIN32
             SwapBuffers( hDC );
        #endif
}
コード例 #22
0
ファイル: COpenGL.cpp プロジェクト: AdmiralCurtiss/snes9x
bool COpenGL::Initialize(HWND hWnd)
{
	int pfdIndex;
	RECT windowRect;

	this->hWnd = hWnd;
	this->hDC = GetDC(hWnd);

	PIXELFORMATDESCRIPTOR pfd=
	{
		sizeof(PIXELFORMATDESCRIPTOR),					// Size Of This Pixel Format Descriptor
		1,												// Version Number
		PFD_DRAW_TO_WINDOW |							// Format Must Support Window
		PFD_SUPPORT_OPENGL |							// Format Must Support OpenGL
		PFD_DOUBLEBUFFER,								// Must Support Double Buffering
		PFD_TYPE_RGBA,									// Request An RGBA Format
		16,												// Select Our Color Depth
		0, 0, 0, 0, 0, 0,								// Color Bits Ignored
		0,												// No Alpha Buffer
		0,												// Shift Bit Ignored
		0,												// No Accumulation Buffer
		0, 0, 0, 0,										// Accumulation Bits Ignored
		16,												// 16Bit Z-Buffer (Depth Buffer)
		0,												// No Stencil Buffer
		0,												// No Auxiliary Buffer
		PFD_MAIN_PLANE,									// Main Drawing Layer
		0,												// Reserved
		0, 0, 0											// Layer Masks Ignored
	};
	PIXELFORMATDESCRIPTOR pfdSel;

	if(!(pfdIndex=ChoosePixelFormat(hDC,&pfd))) {
		DeInitialize();
		return false;
	}
	if(!SetPixelFormat(hDC,pfdIndex,&pfd)) {
		DeInitialize();
		return false;
	}
	if(!(hRC=wglCreateContext(hDC))) {
		DeInitialize();
		return false;
	}
	if(!wglMakeCurrent(hDC,hRC)) {
		DeInitialize();
		return false;
	}

    ogl_LoadFunctions();

	LoadPBOFunctions();

	wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress( "wglSwapIntervalEXT" );
	
	glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glEnable(GL_BLEND);
	glEnable(GL_TEXTURE_2D);

	glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    glOrtho (0.0, 1.0, 0.0, 1.0, -1, 1);
	
	glVertexPointer(2, GL_FLOAT, 0, vertices);
	glTexCoordPointer(2, GL_FLOAT, 0, texcoords);

	cgAvailable = loadCgFunctions();
	if(cgAvailable) {
		cgContext = cgCreateContext();
		cgShader = new CGLCG(cgContext);
	}

    if (ShaderAailable() && NPOTAvailable()) {
        glslShader = new GLSLShader();
    }

	ApplyDisplayChanges();

	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
	glClear(GL_COLOR_BUFFER_BIT);
	SwapBuffers(hDC);

	initDone = true;
	return true;
}
コード例 #23
0
void RenderScreenImpl::swapBuffers()
{
    if (m_hdc)
        SwapBuffers(m_hdc);
}
コード例 #24
0
ファイル: COpenGL.cpp プロジェクト: AdmiralCurtiss/snes9x
void COpenGL::Render(SSurface Src)
{
	SSurface Dst;
	RECT dstRect;
	unsigned int newFilterScale;
	GLenum error;

	if(!initDone) return;

	//create a new draw surface if the filter scale changes
	dstRect = GetFilterOutputSize(Src);
	if(outTextureWidth != dstRect.right || outTextureHeight != dstRect.bottom)
		ChangeDrawSurfaceSize(dstRect.right, dstRect.bottom);

	if(pboFunctionsLoaded) {
		glBindBuffer(GL_PIXEL_UNPACK_BUFFER, drawBuffer);
		Dst.Surface = (unsigned char *)glMapBuffer(GL_PIXEL_UNPACK_BUFFER,GL_READ_WRITE);
	} else {
		Dst.Surface = noPboBuffer;
	}
	Dst.Height = outTextureHeight;
	Dst.Width = outTextureWidth;
	Dst.Pitch = outTextureWidth * 2;

	RenderMethod (Src, Dst, &dstRect);
	if(!Settings.AutoDisplayMessages) {
		WinSetCustomDisplaySurface((void *)Dst.Surface, Dst.Pitch/2, dstRect.right-dstRect.left, dstRect.bottom-dstRect.top, GetFilterScale(CurrentScale));
		S9xDisplayMessages ((uint16*)Dst.Surface, Dst.Pitch/2, dstRect.right-dstRect.left, dstRect.bottom-dstRect.top, GetFilterScale(CurrentScale));
	}

	if(pboFunctionsLoaded)
		glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);

	if(afterRenderHeight != dstRect.bottom || afterRenderWidth != dstRect.right) {
		afterRenderHeight = dstRect.bottom;
		afterRenderWidth = dstRect.right;

		ChangeRenderSize(0,0);
	}

	glBindTexture(GL_TEXTURE_2D,drawTexture);
	glPixelStorei(GL_UNPACK_ROW_LENGTH, outTextureWidth);
	glTexSubImage2D (GL_TEXTURE_2D,0,0,0,dstRect.right-dstRect.left,dstRect.bottom-dstRect.top,GL_RGB,GL_UNSIGNED_SHORT_5_6_5,pboFunctionsLoaded?0:noPboBuffer);

	if(pboFunctionsLoaded)
		glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);

	RECT windowSize, displayRect;
	GetClientRect(hWnd, &windowSize);
	//Get maximum rect respecting AR setting
	displayRect = CalculateDisplayRect(windowSize.right, windowSize.bottom, windowSize.right, windowSize.bottom);

	// GLSL class does all the rendering, no output needed
	if (shader_type == OGL_SHADER_GLSL) {
		glslShader->render(drawTexture, afterRenderWidth, afterRenderHeight, displayRect.left, displayRect.top, displayRect.right - displayRect.left, displayRect.bottom - displayRect.top, wOGLViewportCallback);
	}
	else { // for CG shaders and old style .shader files the last pass is done here, same as no shader
		if(shader_type == OGL_SHADER_CG) {
			xySize inputSize = { (float)afterRenderWidth, (float)afterRenderHeight };
			xySize xywindowSize = { (double)windowSize.right, (double)windowSize.bottom };
			xySize viewportSize = { (double)(displayRect.right - displayRect.left),
				                    (double)(displayRect.bottom - displayRect.top) };
			xySize textureSize = { (double)outTextureWidth, (double)outTextureHeight };
			cgShader->Render(drawTexture, textureSize, inputSize, viewportSize, xywindowSize);
		}
		else if (shader_type == OGL_SHADER_GLSL_OLD) {
			GLint location;

			float inputSize[2] = { (float)afterRenderWidth, (float)afterRenderHeight };
			float outputSize[2] = { (float)(GUI.Stretch ? windowSize.right : afterRenderWidth),
				(float)(GUI.Stretch ? windowSize.bottom : afterRenderHeight) };
			float textureSize[2] = { (float)outTextureWidth, (float)outTextureHeight };
			float frameCnt = (float)++frameCount;
			location = glGetUniformLocation(shaderProgram, "rubyInputSize");
			glUniform2fv(location, 1, inputSize);

			location = glGetUniformLocation(shaderProgram, "rubyOutputSize");
			glUniform2fv(location, 1, outputSize);

			location = glGetUniformLocation(shaderProgram, "rubyTextureSize");
			glUniform2fv(location, 1, textureSize);
		}
		if (Settings.BilinearFilter) {
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		}
		else {
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		}

		glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
		glClear(GL_COLOR_BUFFER_BIT);
		glDrawArrays(GL_QUADS, 0, 4);
    }

	glFlush();
	SwapBuffers(hDC);
	if (GUI.ReduceInputLag)
		glFinish();
}
コード例 #25
0
ファイル: Main.cpp プロジェクト: roblourens/FlowSnake
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE ignoreMe0, LPSTR ignoreMe1, INT ignoreMe2)
{
	HRESULT hr = S_OK;
	HWND hWnd = NULL;
	HDC hDC = NULL;
	HGLRC hRC = NULL;
	MSG msg = {};
	PIXELFORMATDESCRIPTOR pfd;
	
    LARGE_INTEGER previousTime;
    LARGE_INTEGER freqTime;
	double aveDeltaTime = 0.0;

    LPCSTR wndName = "Flow Snake";

	IFC( InitWindow(hWnd, g_width, g_height, wndName) );
    hDC = GetDC(hWnd);

    // Create the GL context.
    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 = 24;
    pfd.cDepthBits = 16;
    pfd.iLayerType = PFD_MAIN_PLANE;
    int pixelFormat = ChoosePixelFormat(hDC, &pfd);
	SetPixelFormat(hDC, pixelFormat, &pfd);
    
	hRC = wglCreateContext(hDC);
    wglMakeCurrent(hDC, hRC);

	IFC( Init() );

    QueryPerformanceFrequency(&freqTime);
    QueryPerformanceCounter(&previousTime);
	
	// -------------------
    // Start the Game Loop
    // -------------------
    while (msg.message != WM_QUIT)
    {
        if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg); 
            DispatchMessage(&msg);
        }
        else
        {
            LARGE_INTEGER currentTime;
            __int64 elapsed;
            double deltaTime;

            QueryPerformanceCounter(&currentTime);
            elapsed = currentTime.QuadPart - previousTime.QuadPart;
            deltaTime = double(elapsed) / freqTime.QuadPart;
			aveDeltaTime = aveDeltaTime * 0.9 + 0.1 * deltaTime;
            previousTime = currentTime;

			IFC( Update(deltaTime) );

			Render();
            SwapBuffers(hDC);
            if (glGetError() != GL_NO_ERROR)
            {
                Error("OpenGL error.\n");
            }
        }
    }

Cleanup:
	if(hRC)  wglDeleteContext(hRC);
	if(hDC)  ReleaseDC(hWnd, hDC);
	if(hWnd) DestroyWindow(hWnd);

	char strBuf[256];
	sprintf_s(strBuf, "Average frame duration = %.3f ms\n", aveDeltaTime*1000.0f); 
	OutputDebugString(strBuf);

    return FAILED(hr);
}
コード例 #26
0
int WINAPI WinMain(	HINSTANCE	hInstance,				// 当前窗口实例
			HINSTANCE	hPrevInstance,				// 前一个窗口实例
			LPSTR		lpCmdLine,				// 命令行参数
			int		nCmdShow)				// 窗口显示状态
{
	MSG	msg;								// Windowsx消息结构
	BOOL	done=FALSE;							// 用来退出循环的Bool 变量
	
	// 提示用户选择运行模式
	if (MessageBox(NULL,"你想在全屏模式下运行么?",  "设置全屏模式",MB_YESNO|MB_ICONQUESTION)==IDNO)
	{
		fullscreen=FALSE;						// FALSE为窗口模式
	}

	// 创建OpenGL窗口
	if (!CreateGLWindow("NeHe's OpenGL程序框架",640,480,16,fullscreen))
	{
		return 0;							// 失败退出
	}

	while(!done)								// 保持循环直到 done=TRUE
	{
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))			// 有消息在等待吗?
		{
			if (msg.message==WM_QUIT)				// 收到退出消息?
			{
				done=TRUE;					// 是,则done=TRUE
			}
			else							// 不是,处理窗口消息
			{
				TranslateMessage(&msg);				// 翻译消息
				DispatchMessage(&msg);				// 发送消息
			}
		}
		else								// 如果没有消息
		{
			// 绘制场景。监视ESC键和来自DrawGLScene()的退出消息
			if (active)						// 程序激活的么?
			{
				if (keys[VK_ESCAPE])				// ESC 按下了么?
				{
					done=TRUE;				// ESC 发出退出信号
				}
				else						// 不是退出的时候,刷新屏幕
				{
					DrawGLScene();				// 绘制场景
					SwapBuffers(hDC);			// 交换缓存 (双缓存)
				}
			}

			if (keys[VK_F1])					// F1键按下了么?
			{
				keys[VK_F1]=FALSE;				// 若是,使对应的Key数组中的值为 FALSE
				KillGLWindow();					// 销毁当前的窗口
				fullscreen=!fullscreen;				// 切换 全屏 / 窗口 模式
				// 重建 OpenGL 窗口
				if (!CreateGLWindow("OpenGL 程序框架",640,480,16,fullscreen))
				{
					return 0;				// 如果窗口未能创建,程序退出
				}
			}
		}
	}

	// 关闭程序
	KillGLWindow();								// 销毁窗口
	return (msg.wParam);							// 退出程序
}
コード例 #27
0
void CGLWindow::OnPaint() 
	{
	static float fX = 0.0f;
	static float fY = 0.0f;

	if(m_hRC != NULL)
		{
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		//fX += 0.015f;
		//fY += 0.01f;
		fX += 1.0f;
		fY += 1.0f;

		if(fX > 360.0f)
			fX = 0.015f;

		if(fY > 360.0f)
			fY = 0.01f;

		glPushMatrix();
		glRotatef(fX, 1.0f, 0.0f, 0.0f);
		glRotatef(fY, 0.0f, 1.0f, 0.0f);

		float fSize = 20.0f;

		// Front face of Cube
		glBindTexture(GL_TEXTURE_2D, m_Sides[0]);
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 1.0f);
			glVertex3f(-fSize, fSize, fSize);
			glTexCoord2f(0.0f, 0.0f);
			glVertex3f(-fSize, -fSize, fSize);
			glTexCoord2f(1.0f, 0.0f);
			glVertex3f(fSize,-fSize, fSize);
			glTexCoord2f(1.0f, 1.0f);
			glVertex3f(fSize,fSize, fSize);
		glEnd();

		// Back face of Cube
		glBindTexture(GL_TEXTURE_2D,  m_Sides[1]);
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 1.0f);
			glVertex3f(fSize,fSize, -fSize);
			glTexCoord2f(0.0f, 0.0f);
			glVertex3f(fSize,-fSize, -fSize);
			glTexCoord2f(1.0f, 0.0f);
			glVertex3f(-fSize, -fSize, -fSize);
			glTexCoord2f(1.0f, 1.0f);
			glVertex3f(-fSize, fSize, -fSize);
		glEnd();

		// Top Face of Cube
		glBindTexture(GL_TEXTURE_2D,  m_Sides[2]);
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 1.0f);
			glVertex3f(-fSize, fSize, fSize);
			glTexCoord2f(0.0f, 0.0f);
			glVertex3f(fSize, fSize, fSize);
			glTexCoord2f(1.0f, 0.0f);
			glVertex3f(fSize, fSize, -fSize);
			glTexCoord2f(1.0f, 1.0f);
			glVertex3f(-fSize, fSize, -fSize);
		glEnd();


		// Bottom Face of Cube
		glBindTexture(GL_TEXTURE_2D,  m_Sides[3]);
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 1.0f);
			glVertex3f(-fSize, -fSize, -fSize);
			glTexCoord2f(0.0f, 0.0f);
			glVertex3f(fSize, -fSize, -fSize);
			glTexCoord2f(1.0f, 0.0f);
			glVertex3f(fSize, -fSize, fSize);
			glTexCoord2f(1.0f, 1.0f);
			glVertex3f(-fSize, -fSize, fSize);
		glEnd();


		// Left hand side of cube
		glBindTexture(GL_TEXTURE_2D,  m_Sides[4]);
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 1.0f);
			glVertex3f(-fSize, fSize, -fSize);
			glTexCoord2f(0.0f, 0.0f);
			glVertex3f(-fSize, -fSize, -fSize);
			glTexCoord2f(1.0f, 0.0f);
			glVertex3f(-fSize, -fSize, fSize);
			glTexCoord2f(1.0f, 1.0f);
			glVertex3f(-fSize, fSize, fSize);
		glEnd();


		// Right hand side of cube
		glBindTexture(GL_TEXTURE_2D,  m_Sides[5]);
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 1.0f);
			glVertex3f(fSize, fSize, fSize);
			glTexCoord2f(0.0f, 0.0f);
			glVertex3f(fSize, -fSize, fSize);
			glTexCoord2f(1.0f, 0.0f);
			glVertex3f(fSize, -fSize, -fSize);
			glTexCoord2f(1.0f, 1.0f);
			glVertex3f(fSize, fSize, -fSize);
		glEnd();

		glPopMatrix();

		GLint eBuffer;
		glGetIntegerv(GL_DRAW_BUFFER, &eBuffer);

		if(eBuffer == GL_FRONT)
			glFinish();
		else
			SwapBuffers(m_hDC);
		}
	else
		{
		CPaintDC dc(this); // device context for painting

		RECT rect;
		GetClientRect(&rect);
		HDC m_hMemDC;
		HBITMAP m_hBitmap, m_hOldBitmap;

		m_hMemDC = CreateCompatibleDC(m_hDC);
	
		// Load the bitmap
		m_hBitmap = LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BM_NOGL));
		m_hOldBitmap = (HBITMAP) SelectObject(m_hMemDC, m_hBitmap);

		// Do the blit for the background
		StretchBlt(m_hDC, 0,0, rect.right, rect.bottom, m_hMemDC, 0, 0, 200, 200,SRCCOPY);

		SelectObject(m_hMemDC, m_hOldBitmap);
		DeleteObject(m_hBitmap);
		::DeleteDC(m_hMemDC);
		}

	ValidateRect(NULL);
	}
コード例 #28
0
ファイル: ShellWin32.cpp プロジェクト: LiberatorUSA/GUCEF
// Flips the OpenGL buffers.
void Shell::FlipBuffers()
{
    SwapBuffers(device_context);
}
コード例 #29
0
int WINAPI WinMain(	HINSTANCE	hInstance,			// Instance
					HINSTANCE	hPrevInstance,		// Previous Instance
					LPSTR		lpCmdLine,			// Command Line Parameters
					int			nCmdShow)			// Window Show State
{
	MSG		msg;									// Windows Message Structure
	BOOL	done=FALSE;								// Bool Variable To Exit Loop

	// Ask The User Which Screen Mode They Prefer
    if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)
	{
		fullscreen=FALSE;							// Windowed Mode
	}

	// Create Our OpenGL Window
	if (!CreateGLWindow("3*3 MagicCube - 毕梦霄",1024,576,16,fullscreen))
	{
		return 0;									// Quit If Window Was Not Created
	}
	//调用API函数使用双冒号前缀
	::SetTimer(hWnd,1,10,NULL);

	::SetTimer(hWnd,2,200,TimerProc);


	while(!done)									// Loop That Runs While done=FALSE|消息循环程序段
	{
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))	// Is There A Message Waiting?|如果有消息我们处理消息,如果没有消息我们绘制场景
		{
			if (msg.message==WM_QUIT)				// Have We Received A Quit Message?
			{
				done=TRUE;							// If So done=TRUE
			}
			else									// If Not, Deal With Window Messages
			{
				TranslateMessage(&msg);				// Translate The Message
				DispatchMessage(&msg);				// Dispatch The Message
			}
		}
		else										// If There Are No Messages
		{
			// Draw The Scene.  Watch For ESC Key And Quit Messages From DrawGLScene()
			// 此主消息循环负责刷新绘图环境
			if ((active && !DrawGLScene()) || keys[VK_ESCAPE])	// Active?  Was There A Quit Received?
			{
				done=TRUE;							// ESC or DrawGLScene Signalled A Quit
			}
			else									// Not Time To Quit, Update Screen
			{
				SwapBuffers(hDC);					// Swap Buffers (Double Buffering)|等同于glFlush()强制刷新,用于交换双缓冲区从而显示更新
			}

			//WndProc只处理事件本身,即把键盘按下或弹起的消息记录到数据结构中,具体处理其含义是在主程序中进行的
			if (keys[VK_F1])						// Is F1 Being Pressed?
			{
				keys[VK_F1]=FALSE;					// If So Make Key FALSE
				KillGLWindow();						// Kill Our Current Window
				fullscreen=!fullscreen;				// Toggle Fullscreen / Windowed Mode
				// Recreate Our OpenGL Window
				if (!CreateGLWindow("这是个彩蛋。!",640,480,16,fullscreen))//这是个彩蛋。
				{
					return 0;						// Quit If Window Was Not Created
				}
			}

			//按方向键可以把魔方上下左右移动
			if(keys[VK_LEFT])
			{
				keys[VK_LEFT]=FALSE;	

				RX -= 0.05f;						//全局X坐标,Z是景深

			}

			if(keys[VK_RIGHT])
			{
				keys[VK_RIGHT]=FALSE;	
				
				RX += 0.05f;

			}

			if(keys[VK_UP])
			{
				keys[VK_UP]=FALSE;	
				
				RY += 0.05f;

			}

			if(keys[VK_DOWN])
			{
				keys[VK_DOWN]=FALSE;	
				
				RY -= 0.05f;
	
			}
		}
	}

	// Shutdown
	KillGLWindow();									// Kill The Window
	return (msg.wParam);							// Exit The Program
}
コード例 #30
0
ファイル: editor.cpp プロジェクト: dmakarov/rasterizer
void EditorCanvas::paint()
{
  auto status = SetCurrent(*context);
  assert(status);
  int w, h;
  GetClientSize(&w, &h);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(0, w, -h, 0, 0, 1);
  glClearColor(0.f, 0.f, 0.f, 0.f);
  glClear(GL_COLOR_BUFFER_BIT);
  // add a red border if it is a keyframe
  if (scene.anyKeyframe(frame)) {
    glLineWidth(8);
    glColor3d(1, 0, 0);
    glBegin(GL_LINE_STRIP);
    {
      glVertex2d(    1,     -1);
      glVertex2d(    1, -h + 1);
      glVertex2d(w - 1, -h + 1);
      glVertex2d(w - 1,     -1);
      glVertex2d(    1,     -1);
    }
    glEnd();
  }
  glLineWidth(1);
  auto polygons = scene.getPolygons();
  auto selected = scene.getSelectedPolygon();
  for (auto& p : polygons) {
    std::vector<Point> vertices;
    auto color = p->getVertices(frame, vertices);
    glColor3d(color.get_red(), color.get_green(), color.get_blue());
    glLineWidth(selected == p ? 3 : 1);
    // draw the edges
    glBegin(GL_LINE_STRIP);
    {
      for (auto& v : vertices) {
        glVertex2d(v.x, -v.y);
      }
      glVertex2d(vertices[0].x, -vertices[0].y);
    }
    glEnd();
    // now draw the vertices on top of the lines
    if (selected == p) {
      auto v = scene.getSelectedVertex();
      glBegin(GL_LINES);
      {
        decltype(v) j = 0;
        for (auto& p : vertices) {
          glColor3d(0, 1, j++ == v ? 0 : 1);
          glVertex2d(p.x + 5, -p.y);
          glVertex2d(p.x - 5, -p.y);
          glVertex2d(p.x, -p.y + 5);
          glVertex2d(p.x, -p.y - 5);
        }
      }
      glEnd();
    }
  }

  if (state == State::CENTER ||
      state == State::ROTATE ||
      state == State::SCALE) {
    glBegin(GL_LINES);
    {
      glColor3d(0.5, 0.5, 0.5);
      auto rc = scene.getCenter();
      auto x = static_cast<int>(rc.x);
      auto y = static_cast<int>(rc.y);
      glVertex2d(x + 5, -y);
      glVertex2d(x - 5, -y);
      glVertex2d(x, -y + 5);
      glVertex2d(x, -y - 5);
    }
    glEnd();
  } else if (state == State::DRAW) { // draw the object currently being created
    glLineWidth(3);
    // first draw the edges
    auto p = scene.getActivePolygon();
    const auto& c = p->getColor();
    glColor3d(c.get_red(), c.get_green(), c.get_blue());
    auto& vertices = p->keyframes[0].vertices;
    glBegin(GL_LINE_STRIP);
    {
      for (auto& v : vertices) {
        glVertex2d(v.x, -v.y);
      }
    }
    glEnd();
    // now draw the vertices
    glColor3d(0, 1, 1);
    glBegin(GL_LINES);
    {
      for (auto& v : vertices) {
        glVertex2d(v.x + 5, -v.y);
        glVertex2d(v.x - 5, -v.y);
        glVertex2d(v.x, -v.y + 5);
        glVertex2d(v.x, -v.y - 5);
      }
    }
    glEnd();
  }

  glFlush();
  status = SwapBuffers();
  assert(status);
}