Skip to content

yocover/start-learning-opengl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

start-learning-opengl

learnopengl-cn 学习示例 --> IDE:vscode

示例截图

02_hello_triangle 02_hello_triangle 03_hello_triangle_exercise 04_shader_glsl_01 04_shader_glsl_02 05_shader_class
07_load_texture 08_load_texture_exercise 09_transform 10_use_plane_geometry 11_use_sphere_geometry 12_use_box_geometry
13_model_view_projection 14_use_image_ui 15_mvp_matrix_exercise 16_use_camera 17_use_camera_class 18_light_scene
19_basic_lighting 20_light_material 21_light_map 22_light_map_exercise 23_direction_light 24_point_light
25_spot_light 26_multiple_lights 27_load_model 28_depth_testing 29_stencil_testing 30_blending
31_face_culling 32_frame_buffers 33_cube_maps 34_env_mapping 35_advanced_glsl 36_geometry_shader
37_instancing 38_anti_aliasing 39_blinn_phong 40_gamma_corre 41_shadow_mapping 42_point_shadow
43_normal_mapping 43_normal_tangent 44_parallax_mapping 45_heigh_dynamic_range 46_bloom 47_deferred_shading
48_ssao_shading 49_pbr_light 49_pbr_light 50_diffuse_ibl 51_specular_ibl 51_specular_ibl

windows 下 vscode 配置 OpenGL 开发环境

参考

  • windows 需安装 MinGW, install gcc、g++、gdb 和 mingw32-make 并 进入到 MinGW\bin 文件夹下 把 mingw32-make.exe 修改成 make.exe

    MinGW 不要下载 MinGW-w64因为后面可能会出现问题 MinGW,即 Minimalist GNU For Windows。它是一些头文件和端口库的集合,该集合允许人们在没有第三方动态链接库的情况下使用 GCC 产生 Win32 程序。

  • vscode 插件 C/C++C/C++ Project Generator

  • glfw 下载 Windows pre-compiled binaries

    选择Windows pre-compiled binaries,因为我们使用的 MinGW 所以选择 32-bit Windows binaries 对于 Ubuntu,通过 sudo apt install libglfw3-dev libglfw3 安装 glfw

  • glad 在线服务 生成静态库

    > gcc ./src/glad.c -c -I ./include/ // 生成 .o文件
    > ar -rc libglad.a glad.o           // 生成我们所需要的 .a文件
    

    将生成的 libglad.a 复制到 lib 文件下

  • glm 复制到 include 目录下

  • imgui 复制到 include 目下,Makefile 中添加以下命令

    # define the C source files
    SOURCES		:= $(wildcard $(patsubst %,%/*.cpp, $(SOURCEDIRS)))
    SOURCES	+= include/imgui/imgui_impl_glfw.cpp include/imgui/imgui_impl_opengl3.cpp
    SOURCES	+= include/imgui/imgui.cpp include/imgui/imgui_demo.cpp include/imgui/imgui_draw.cpp include/imgui/imgui_widgets.cpp
  • assimp 下载已编译好的文件 Assimp3-1-1_MinGW4-8-1_Win32.zip

    对于 Ubuntu,通过 sudo apt install libassimp-dev 安装 assimp

  • 参考 Makefile 文件

示例

1. Run 和 Clean

测试代码

#include <glad/glad.h>
#include <GLFW/glfw3.h>

#include <iostream>

void framebuffer_size_callback(GLFWwindow *window, int width, int height);
void processInput(GLFWwindow *window);

const unsigned int SCR_WIDTH = 800;
const unsigned int SCR_HEIGHT = 600;

int main()
{
	glfwInit();
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

	GLFWwindow *window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
	if (window == NULL)
	{
		std::cout << "Failed to create GLFW window" << std::endl;
		glfwTerminate();
		return -1;
	}
	glfwMakeContextCurrent(window);
	glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);

	if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
	{
		std::cout << "Failed to initialize GLAD" << std::endl;
		return -1;
	}

	while (!glfwWindowShouldClose(window))
	{
		processInput(window);
		glfwSwapBuffers(window);
		glfwPollEvents();
	}

	glfwTerminate();
	return 0;
}

void processInput(GLFWwindow *window)
{
	if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
		glfwSetWindowShouldClose(window, true);
}

void framebuffer_size_callback(GLFWwindow *window, int width, int height)
{
	glViewport(0, 0, width, height);
}

执行命令 run 编译和运行.exe 程序

make run dir=01_test_glfw

执行命令 clean 删除 .exe 和对应文件夹下的.o 文件

make clean dir=01_test_glfw

2. Debug

需要设置调试一个文件 修改 tasks.json下面的条目

 "label": "build",
  "type": "shell",
  "group": {
      "kind": "build",
      "isDefault": true
  },
  "windows": {
      "command": "powershell",
      "args": [
          "-c",
          "make dir=01_test_glfw", // 调式 01_test_glfw/main.cpp
      ]
  },

About

Learn opengl together

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published