VS2010 配置OpenGL环境 及 Release编译环境

创建一个OpenGL窗口

#include <Windows.h>
#include <stdio.h>
#include <tchar.h>
#include "gl3w.h"
#include "glfw3.h"
#pragma comment(lib,"glfw3.lib")

static void error_callback(int error, const char* description);

int APIENTRY _tWinMain(HINSTANCE hInstance,
	HINSTANCE hPrevInstance,
	LPTSTR    lpCmdLine,
	int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

	//////////////////////////////////////////////////////////////////////////
	glfwSetErrorCallback(error_callback);
	if (!glfwInit())
		return 1;
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
	GLFWwindow* window = glfwCreateWindow(1280, 720, "ImGui OpenGL3 example", NULL, NULL);
	glfwMakeContextCurrent(window);
	gl3wInit();
	while (!glfwWindowShouldClose(window))
	{
		glfwPollEvents();
		int display_w, display_h;
		glfwGetFramebufferSize(window, &display_w, &display_h);
		glViewport(0, 0, display_w, display_h);
		glClearColor(255, 0,255, 0);
		glClear(GL_COLOR_BUFFER_BIT);
		//绘制部分

		//
		glfwSwapBuffers(window);
	}

	glfwTerminate();

	return TRUE;
}


static void error_callback(int error, const char* description)
{
	fprintf(stderr, "Error %d: %s\n", error, description);
}

添加 OpenGL头文件和LIB,在OpenGL文件夹

1.解决方案-VC++目录 包含目录 添加 OpenGL\include

2.解决方案-VC++目录 库目录 添加 OpenGL\lib

3. 解决方案-C/C++-代码生成 选择 多线程 DLL (/MD)(重要)必须选择

4.解决方案-C/C++-预处理器-预处理器定义 添加 GLEW_STATIC(静态编译要添加)

5.解决方案-连接器-输入-附加依赖项 添加 opengl32.lib

猜你喜欢

转载自blog.csdn.net/AVAado/article/details/81172258
今日推荐