예제 #1
0
파일: main.cpp 프로젝트: itop/slider-freq
int main(int argc, char *argv[])
{
	if(!glfwInit())
    {
        return -1;
    }

    //Create GL context
    glfwOpenWindow(WINDOW_WIDTH, WINDOW_HEIGHT, 8, 8, 8, 8, 8, 8, GLFW_WINDOW);

    glEnable(GL_CULL_FACE);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);

    //Initialize GLEW
    GLenum err = glewInit();
    if(err != GLEW_NO_ERROR)
    {
        const unsigned char *str = glewGetErrorString(err);
        return -1;
    }

    //Callbacks
    glfwSetWindowSizeCallback(resize);
    glfwSetMouseButtonCallback(mousebutton);
    glfwSetMousePosCallback(mousepos);

    glClearColor(0.1,0.1,0.1,1.0);

    app.Init();
    app.OnResize(WINDOW_WIDTH, WINDOW_HEIGHT);

    float start = 0;
    float end = 0;
    float delta = 0;

	while(1) {
        start = glfwGetTime();
        if(glfwGetKey(GLFW_KEY_ESC)) break;

        //Clear the existing screen data
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        if(soundDoneFlag)
        {
            app.OnPlayComplete();
            soundDoneFlag = false;
        }

        //Update app logic
		app.Update(delta);

        //Flip the screen buffer
        glfwSwapBuffers();
        end = glfwGetTime();
        delta = end - start;
	}

    app.ShutDown();

	return 0;
}
예제 #2
0
LRESULT CALLBACK MainApp::WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	LRESULT result = 0;

	if (message == WM_CREATE)
	{
		LPCREATESTRUCT pcs = (LPCREATESTRUCT)lParam;
		MainApp *pMainApp = (MainApp *)pcs->lpCreateParams;

		::SetWindowLongPtrW(
			hwnd,
			GWLP_USERDATA,
			PtrToUlong(pMainApp)
			);

		result = 1;
	}
	else
	{
		MainApp *pMainApp = reinterpret_cast<MainApp *>(static_cast<LONG_PTR>(
			::GetWindowLongPtrW(
			hwnd,
			GWLP_USERDATA
			)));

		bool wasHandled = false;

		if (pMainApp)
		{
			switch (message)
			{
				case WM_TIMER:
				{
					pMainApp->OnTimer();
				}
					result = 0;
					wasHandled = true;
					break;
				case WM_SIZE:
				{
					UINT width = LOWORD(lParam);
					UINT height = HIWORD(lParam);
					pMainApp->OnResize(width, height);
				}
					result = 0;
					wasHandled = true;
					break;

				case WM_DISPLAYCHANGE:
				{
					InvalidateRect(hwnd, NULL, FALSE);
				}
					result = 0;
					wasHandled = true;
					break;

				case WM_PAINT:
				{
					pMainApp->OnRender();
					ValidateRect(hwnd, NULL);
				}
					result = 0;
					wasHandled = true;
					break;

				case WM_DESTROY:
				{
					PostQuitMessage(0);
				}
					result = 1;
					wasHandled = true;
					break;

				case WM_KEYDOWN:
				{
					switch (wParam){
						case VK_ESCAPE: ExitProcess(0);
					}
				}
			}
		}

		if (!wasHandled)
		{
			result = DefWindowProc(hwnd, message, wParam, lParam);
		}
	}

	return result;
}
예제 #3
0
파일: main.cpp 프로젝트: itop/slider-freq
void GLFWCALL resize(int w, int h)
{
    app.OnResize(w,h);
}