コード例 #1
0
ファイル: Main.cpp プロジェクト: lambdataro/Windows-OpenGL45
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    static HGLRC hglrc;
    static GLuint program;
    static GLuint width, height, texture;
    static GLuint imgWidth, imgHeight;

    switch (uMsg)
    {
    case WM_CREATE:
        hglrc = CreateOpenGLContext(hwnd);
        InitOpenGLFunctions();
        RegisterErrorCallback();
        program = LoadShader();

        width = glGetUniformLocation(program, "width");
        height = glGetUniformLocation(program, "height");

        texture = glGetUniformLocation(program, "texture");
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, LoadTexture(ID_TEXTURE));
        glUniform1i(texture, 0);

        imgWidth = glGetUniformLocation(program, "img_width");
        imgHeight = glGetUniformLocation(program, "img_height");
        glUniform1f(imgWidth, 400.0f);
        glUniform1f(imgHeight, 300.0f);

        SetupModel(hwnd);
        glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
        return 0;

    case WM_PAINT:
        Paint(hwnd);
        return 0;

    case WM_SIZE:
        glViewport(0, 0, LOWORD(lParam), HIWORD(lParam));
        glUniform1f(width, LOWORD(lParam));
        glUniform1f(height, HIWORD(lParam));
        InvalidateRect(hwnd, nullptr, FALSE);
        return 0;

    case WM_DESTROY:
        DeleteOpenGLContext(hglrc);
        PostQuitMessage(0);
        return 0;

    default:
        return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }
}
コード例 #2
0
ファイル: Main.cpp プロジェクト: lambdataro/Windows-OpenGL45
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    static HGLRC hglrc;

    switch (uMsg)
    {
    case WM_CREATE:
        hglrc = CreateOpenGLContext(hwnd);
        return 0;

    case WM_DESTROY:
        DeleteOpenGLContext(hglrc);
        PostQuitMessage(0);
        return 0;

    default:
        return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }
}
コード例 #3
0
ファイル: main.cpp プロジェクト: Kraetyz/Luaprojekt
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
{
	MSG msg = { 0 };
	window = InitWindow(hInstance); //1. Skapa fönster


	AllocConsole();

	HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
	int hCrt = _open_osfhandle((long)handle_out, _O_TEXT);
	FILE* hf_out = _fdopen(hCrt, "w");
	setvbuf(hf_out, NULL, _IONBF, 1);
	*stdout = *hf_out;

	HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
	hCrt = _open_osfhandle((long)handle_in, _O_TEXT);
	FILE* hf_in = _fdopen(hCrt, "r");
	setvbuf(hf_in, NULL, _IONBF, 128);
	*stdin = *hf_in;

	if (window)
	{
		HDC hDC = GetDC(window);
		HGLRC hRC = CreateOpenGLContext(window); //2. Skapa och koppla OpenGL context

		glewInit(); //3. Initiera The OpenGL Extension Wrangler Library (GLEW)
		//glEnable(GL_CULL_FACE);

		SetViewport(); //4. Sätt viewport

		ShowWindow(window, nCmdShow);

		state = new Menu();

		buttonState = luaL_newstate();
		luaL_openlibs(buttonState);

		if (luaL_loadfile(buttonState, "Error.lua") || lua_pcall(buttonState, 0, 0, 0))
		{
			std::cout << "Error handler failed" << std::endl;
			std::cerr << lua_tostring(buttonState, -1) << std::endl;
			lua_pop(buttonState, 1);
		}
		lua_getglobal(buttonState, "ErrorHandler");
		int luaErrorHandlerPos = lua_gettop(buttonState);

		registerLuaFuncs();

		if (luaL_loadfile(buttonState, "menuButtons.txt") || lua_pcall(buttonState, 0, 0, luaErrorHandlerPos))
		{
			std::cout << "erroooor" << std::endl;
			std::cout << lua_tostring(buttonState, -1) << std::endl;
			lua_pop(buttonState, 1);
		}
		setupButtons();
		lua_pop(buttonState, 1);

		while (WM_QUIT != msg.message)
		{
			if (msg.message == WM_LBUTTONDOWN)
				clickUpdate();
			if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE))
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}

			else
			{
				Update(); //9. Rendera
				SwapBuffers(hDC); //10. Växla front- och back-buffer
			}
		}

		wglMakeCurrent(NULL, NULL);
		ReleaseDC(window, hDC);
		wglDeleteContext(hRC);
		DestroyWindow(window);
	}

	lua_close(buttonState);

	return (int)msg.wParam;
}