Code Monkey home page Code Monkey logo

opengl's Introduction

OpenGL

learnopengl-cn 学习示例 --> IDE:Visual Studio Code

示例截图

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 需安装 tdm64-gcc (gcc & g++ -v == 10.3.0),进入到 C:\TDM-GCC-64\bin 文件夹下备份 mingw32-make.exe 并修改成 make.exe,作为 Makefile指定编译器

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

  • glfw库

    对于 Windows,下载 Windows pre-compiled binaries,因为我们使用的 TDM-GCC-64 所以选择 64-bit Windows binaries,注意需要将.dll文件移动至output文件夹,.a文件移动至lib文件夹,include中文件复制至项目下的include文件夹

    对于 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 文件下,include中文件复制至项目下的include文件夹

  • 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 库

    对于 Windows,需参考相关编译流程自行编译,仓库中所存为Assimp-v5.3.1.zip于Windows环境下经过Cmake-GUI-v3.26.3编译得到

    对于 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
      ]
  },

opengl's People

Contributors

pineapple274 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.