├── .gitignore ├── 000 - Apple M1 配置测试 ├── .idea │ ├── .gitignore │ ├── .name │ ├── 000 - Apple M1 配置测试.iml │ ├── misc.xml │ ├── modules.xml │ └── vcs.xml ├── CMakeLists.txt ├── glad │ ├── include │ │ ├── KHR │ │ │ └── khrplatform.h │ │ └── glad │ │ │ └── glad.h │ └── src │ │ └── glad.c └── main.cpp ├── 001_OpenGLWidget_HelloWidget └── 001_HelloWidget │ ├── 001_HelloWidget.pro │ ├── axbopenglwidget.cpp │ ├── axbopenglwidget.h │ ├── main.cpp │ ├── mainwindow.cpp │ ├── mainwindow.h │ └── mainwindow.ui ├── 002_Triangle_VAO_VBO └── 002_Triangle_VAO_VBO │ ├── 002_Triangle_VAO_VBO.pro │ ├── axbopenglwidget.cpp │ ├── axbopenglwidget.h │ ├── main.cpp │ ├── mainwindow.cpp │ ├── mainwindow.h │ └── mainwindow.ui ├── 002_Triangle_VAO_VBO_on_M1_Mac ├── .DS_Store └── 002_Triangle_VAO_VBO │ ├── 002_Triangle_VAO_VBO_m1.pro │ ├── axbopenglwidget.cpp │ ├── axbopenglwidget.h │ ├── main.cpp │ ├── mainwindow.cpp │ ├── mainwindow.h │ └── mainwindow.ui ├── 003_Triangle_EBO ├── 003_Triangle_EBO.pro ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h └── mainwindow.ui ├── 005_Two_triangle_exercise ├── 005_Two_triangle_exercise.pro ├── axbopenglwidget.cpp ├── axbopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h └── mainwindow.ui ├── 010_Qt_UI_with_OpenGL ├── 010_Qt_UI_with_OpenGL.pro ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h └── mainwindow.ui ├── 011_QOpenGLShaderProgram ├── 011_QOpenGLShaderProgram.pro ├── ShaderSource │ ├── source.frag │ └── source.vert ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui └── resource.qrc ├── 020_GLSL_in_out ├── 020_GLSL_in_out.pro ├── ShaderSource │ ├── source.frag │ └── source.vert ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui └── resource.qrc ├── 021_GLSL_layout ├── 021_GLSL_layout.pro ├── ShaderSource │ ├── source.frag │ └── source.vert ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui └── resource.qrc ├── 022_GLSL_uniform ├── 022_GLSL_uniform.pro ├── ShaderSource │ ├── source.frag │ └── source.vert ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui └── resource.qrc ├── 023_GLSL_more_Attrib ├── 023_GLSL_more_attrib.pro ├── ShaderSource │ ├── source.frag │ └── source.vert ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui └── resource.qrc ├── 024_GLSL_exercise ├── 024_GLSL_exercise.pro ├── ShaderSource │ ├── source.frag │ └── source.vert ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui └── resource.qrc ├── 030_Texel ├── 030_Texel.pro ├── Pictures │ ├── nekosilverfox.jpg │ └── wall.jpg ├── ShaderSource │ ├── source.frag │ └── source.vert ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui └── resource.qrc ├── 031_Texel_wrap ├── 031_Texel_wrap.pro ├── Pictures │ ├── nekosilverfox.jpg │ ├── nekosilverfox_bk.jpg │ └── wall.jpg ├── ShaderSource │ ├── source.frag │ └── source.vert ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui └── resource.qrc ├── 032_Texture_Filtering ├── 032_Texture_Filtering.pro ├── Pictures │ ├── nekosilverfox.jpg │ ├── nekosilverfox_bk.jpg │ └── wall.jpg ├── ShaderSource │ ├── source.frag │ └── source.vert ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui └── resource.qrc ├── 033_Texture_exercise ├── 033_Texture_exercise.pro ├── Pictures │ ├── nekosilverfox.png │ ├── nekosilverfox_bk.jpg │ └── wall.jpg ├── ShaderSource │ ├── source.frag │ └── source.vert ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui └── resource.qrc ├── 040_Rotate_and_Move ├── 040_Rotate_and_Move.pro ├── Pictures │ ├── nekosilverfox.png │ ├── nekosilverfox_bk.jpg │ └── wall.jpg ├── ShaderSource │ ├── source.frag │ └── source.vert ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui └── resource.qrc ├── 045_3D ├── 045_3D.pro ├── Pictures │ ├── nekosilverfox.png │ ├── nekosilverfox_bk.jpg │ └── wall.jpg ├── ShaderSource │ ├── source.frag │ └── source.vert ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui └── resource.qrc ├── 046_3D_exercise ├── 046_3D_exercise.pro ├── Pictures │ ├── nekosilverfox.png │ ├── nekosilverfox_bk.jpg │ └── wall.jpg ├── ShaderSource │ ├── source.frag │ └── source.vert ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui └── resource.qrc ├── 047_3D_Camera ├── 047_3D_Camera.pro ├── Pictures │ ├── nekosilverfox.png │ ├── nekosilverfox_bk.jpg │ └── wall.jpg ├── ShaderSource │ ├── source.frag │ └── source.vert ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui └── resource.qrc ├── 048_3D_Move_camera ├── 048_3D_Move_camera.pro ├── Pictures │ ├── nekosilverfox.png │ ├── nekosilverfox_bk.jpg │ └── wall.jpg ├── ShaderSource │ ├── source.frag │ └── source.vert ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui └── resource.qrc ├── 049_Camera_OOP ├── 049_Camera_OOP.pro ├── Pictures │ ├── nekosilverfox.png │ ├── nekosilverfox_bk.jpg │ └── wall.jpg ├── ShaderSource │ ├── source.frag │ └── source.vert ├── camera.cpp ├── camera.hpp ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui └── resource.qrc ├── 055_3D_Sphere ├── 055_3D_Sphere.pro ├── Pictures │ ├── nekosilverfox.png │ ├── nekosilverfox_bk.jpg │ └── wall.jpg ├── ShaderSource │ ├── source.frag │ ├── source.vert │ ├── sphere.frag │ └── sphere.vert ├── camera.cpp ├── camera.hpp ├── cube.cpp ├── cube.h ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── resource.qrc ├── sphere.cpp └── sphere.h ├── 056_3D_Sphere_and_Cube ├── 056_3D_Sphere_and_Cube.pro ├── ShaderSource │ ├── cube.frag │ ├── cube.vert │ ├── source.frag │ ├── source.vert │ ├── sphere.frag │ └── sphere.vert ├── camera.cpp ├── camera.hpp ├── cube.cpp ├── cube.h ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── resource.qrc ├── sphere.cpp └── sphere.h ├── 057_3D_Sphere_Cube_Cone ├── 057_3D_Sphere_Cube_Cone.pro ├── ShaderSource │ ├── cone.frag │ ├── cone.vert │ ├── cube.frag │ ├── cube.vert │ ├── source.frag │ ├── source.vert │ ├── sphere.frag │ └── sphere.vert ├── camera.cpp ├── camera.hpp ├── cone.cpp ├── cone.hpp ├── cube.cpp ├── cube.hpp ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── resource.qrc ├── sphere.cpp └── sphere.hpp ├── 057_3D_Sphere_Cube_Cone_AppleSoc ├── 057_3D_Sphere_Cube_Cone.pro ├── ShaderSource │ ├── cone.frag │ ├── cone.vert │ ├── cube.frag │ ├── cube.vert │ ├── source.frag │ ├── source.vert │ ├── sphere.frag │ └── sphere.vert ├── camera.cpp ├── camera.hpp ├── cone.cpp ├── cone.hpp ├── cube.cpp ├── cube.hpp ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── resource.qrc ├── sphere.cpp └── sphere.hpp ├── 060_Lighting_init ├── 060_Lighting_init.pro ├── ShaderSource │ ├── cone.frag │ ├── cone.vert │ ├── cube.frag │ ├── cube.vert │ ├── light.frag │ ├── light.vert │ ├── source.frag │ ├── source.vert │ ├── sphere.frag │ └── sphere.vert ├── camera.cpp ├── camera.hpp ├── cone.cpp ├── cone.hpp ├── cube.cpp ├── cube.hpp ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── resource.qrc ├── sphere.cpp └── sphere.hpp ├── 060_Lighting_init_AppleSoc ├── 060_Lighting_init_AppleSoc.pro ├── ShaderSource │ ├── cone.frag │ ├── cone.vert │ ├── cube.frag │ ├── cube.vert │ ├── light.frag │ ├── light.vert │ ├── source.frag │ ├── source.vert │ ├── sphere.frag │ └── sphere.vert ├── camera.cpp ├── camera.hpp ├── cone.cpp ├── cone.hpp ├── cube.cpp ├── cube.hpp ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── light.cpp ├── light.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── resource.qrc ├── sphere.cpp └── sphere.hpp ├── 061_Light_Phong ├── 061_Light_Phong.pro ├── ShaderSource │ ├── cone.frag │ ├── cone.vert │ ├── cube.frag │ ├── cube.vert │ ├── light.frag │ ├── light.vert │ ├── source.frag │ ├── source.vert │ ├── sphere.frag │ └── sphere.vert ├── camera.cpp ├── camera.hpp ├── cone.cpp ├── cone.hpp ├── cube.cpp ├── cube.hpp ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── light.cpp ├── light.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── resource.qrc ├── sphere.cpp └── sphere.hpp ├── 062_Light_Phong_move_light ├── 062_Light_Phong_move_light.pro ├── ShaderSource │ ├── cone.frag │ ├── cone.vert │ ├── cube.frag │ ├── cube.vert │ ├── light.frag │ ├── light.vert │ ├── source.frag │ ├── source.vert │ ├── sphere.frag │ └── sphere.vert ├── camera.cpp ├── camera.hpp ├── cone.cpp ├── cone.hpp ├── cube.cpp ├── cube.hpp ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── light.cpp ├── light.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── resource.qrc ├── sphere.cpp └── sphere.hpp ├── 065_Light_Material ├── 065_Light_Material.pro ├── ShaderSource │ ├── cone.frag │ ├── cone.vert │ ├── cube.frag │ ├── cube.vert │ ├── light.frag │ ├── light.vert │ ├── source.frag │ ├── source.vert │ ├── sphere.frag │ └── sphere.vert ├── camera.cpp ├── camera.hpp ├── cone.cpp ├── cone.hpp ├── cube.cpp ├── cube.hpp ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── light.cpp ├── light.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── resource.qrc ├── sphere.cpp └── sphere.hpp ├── 066_Light_Texture_Map ├── 066_Light_Texture_Map.pro ├── Picture │ ├── wood_box.png │ └── wood_box_specular_map.png ├── ShaderSource │ ├── cone.frag │ ├── cone.vert │ ├── cube.frag │ ├── cube.vert │ ├── light.frag │ ├── light.vert │ ├── source.frag │ ├── source.vert │ ├── sphere.frag │ └── sphere.vert ├── camera.cpp ├── camera.hpp ├── cone.cpp ├── cone.hpp ├── cube.cpp ├── cube.hpp ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── light.cpp ├── light.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── resource.qrc ├── sphere.cpp └── sphere.hpp ├── 067_Light_Texture_Map_exercise ├── 067_Light_Texture_Map_exercise.pro ├── Picture │ ├── lighting_maps_specular_color.png │ ├── matrix.jpg │ ├── wood_box.png │ └── wood_box_specular_map.png ├── ShaderSource │ ├── cone.frag │ ├── cone.vert │ ├── cube.frag │ ├── cube.vert │ ├── light.frag │ ├── light.vert │ ├── source.frag │ ├── source.vert │ ├── sphere.frag │ └── sphere.vert ├── camera.cpp ├── camera.hpp ├── cone.cpp ├── cone.hpp ├── cube.cpp ├── cube.hpp ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── light.cpp ├── light.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── resource.qrc ├── sphere.cpp └── sphere.hpp ├── 068_Light_Texture_Map_All_Shape ├── 068_Light_Texture_Map_All_Shape.pro ├── Picture │ ├── light.png │ ├── poly_specular_map.png │ ├── poly_tex.png │ ├── wood_box.png │ └── wood_box_specular_map.png ├── ShaderSource │ ├── cone.frag │ ├── cone.vert │ ├── cube.frag │ ├── cube.vert │ ├── light.frag │ ├── light.vert │ ├── source.frag │ ├── source.vert │ ├── sphere.frag │ └── sphere.vert ├── camera.cpp ├── camera.hpp ├── cone.cpp ├── cone.hpp ├── cube.cpp ├── cube.hpp ├── foxmath.h ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── light.cpp ├── light.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── resource.qrc ├── sphere.cpp └── sphere.hpp ├── 103_GLSL_FrontFacing ├── 103_GLSL_FrontFacing.pro ├── Picture │ ├── light.png │ ├── poly_specular_map.png │ ├── poly_tex.png │ ├── wood_box.png │ └── wood_box_specular_map.png ├── ShaderSource │ ├── cone.frag │ ├── cone.vert │ ├── cube.frag │ ├── cube.vert │ ├── light.frag │ ├── light.vert │ ├── source.frag │ ├── source.vert │ ├── sphere.frag │ └── sphere.vert ├── camera.cpp ├── camera.hpp ├── cone.cpp ├── cone.hpp ├── cube.cpp ├── cube.hpp ├── foxmath.h ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── light.cpp ├── light.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── resource.qrc ├── sphere.cpp └── sphere.hpp ├── 110_Geometry_Shader ├── 110_Geometry_Shader.pro ├── ShaderSource │ ├── source.frag │ ├── source.geom │ └── source.vert ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui └── resource.qrc ├── 111_Geometry_House ├── 111_Geometry_House.pro ├── ShaderSource │ ├── source.frag │ ├── source.geom │ └── source.vert ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui └── resource.qrc ├── 112_Geometry_Bezier_2D ├── 112_Geometry_Bezier_2D.pro ├── Picture │ ├── light.png │ ├── poly_specular_map.png │ ├── poly_tex.png │ ├── wood_box.png │ └── wood_box_specular_map.png ├── ShaderSource │ ├── cone.frag │ ├── cone.geom │ ├── cone.vert │ ├── cube.frag │ ├── cube.vert │ ├── light.frag │ ├── light.vert │ ├── source.frag │ ├── source.vert │ ├── sphere.frag │ ├── sphere.geom │ └── sphere.vert ├── camera.cpp ├── camera.hpp ├── cone.cpp ├── cone.hpp ├── cube.cpp ├── cube.hpp ├── foxmath.h ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── light.cpp ├── light.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── resource.qrc ├── sphere.cpp └── sphere.hpp ├── 112_Geometry_normal_ explode ├── 112_Geometry_normal_ explode.pro ├── Picture │ ├── light.png │ ├── poly_specular_map.png │ ├── poly_tex.png │ ├── wood_box.png │ └── wood_box_specular_map.png ├── ShaderSource │ ├── cone.frag │ ├── cone.geom │ ├── cone.vert │ ├── cube.frag │ ├── cube.vert │ ├── light.frag │ ├── light.vert │ ├── source.frag │ ├── source.vert │ ├── sphere.frag │ ├── sphere.geom │ └── sphere.vert ├── camera.cpp ├── camera.hpp ├── cone.cpp ├── cone.hpp ├── cube.cpp ├── cube.hpp ├── foxmath.h ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── light.cpp ├── light.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── resource.qrc ├── sphere.cpp └── sphere.hpp ├── 115_Geometry_Sphere_change ├── 115_Geometry_shape_change.pro ├── Picture │ ├── ball.png │ └── light.png ├── ShaderSource │ ├── light.frag │ ├── light.vert │ ├── sphere.frag │ ├── sphere.geom │ └── sphere.vert ├── camera.cpp ├── camera.hpp ├── foxmath.h ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── light.cpp ├── light.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── resource.qrc ├── sphere.cpp └── sphere.hpp ├── 116_Geometry_Cone_change ├── 116_Geometry_Cone_change.pro ├── Picture │ └── light.png ├── ShaderSource │ ├── cone.frag │ ├── cone.geom │ ├── cone.vert │ ├── light.frag │ ├── light.vert │ ├── sphere.frag │ └── sphere.vert ├── camera.cpp ├── camera.hpp ├── cone.cpp ├── cone.hpp ├── foxmath.h ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── light.cpp ├── light.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── resource.qrc ├── sphere.cpp └── sphere.hpp ├── 117_Geometry_Cone2Rocket ├── 117_Geometry_Cone2Rocket.pro ├── Picture │ └── light.png ├── ShaderSource │ ├── cone.frag │ ├── cone.geom │ ├── cone.vert │ ├── light.frag │ ├── light.vert │ ├── sphere.frag │ └── sphere.vert ├── camera.cpp ├── camera.hpp ├── cone.cpp ├── cone.hpp ├── foxmath.h ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── light.cpp ├── light.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── resource.qrc ├── sphere.cpp └── sphere.hpp ├── 117_Geometry_Cone2Rocket_Winonws ├── 117_Geometry_Cone2Rocket_Winonws.pro ├── Picture │ └── light.png ├── ShaderSource │ ├── cone.frag │ ├── cone.geom │ ├── cone.vert │ ├── light.frag │ ├── light.vert │ ├── sphere.frag │ └── sphere.vert ├── camera.cpp ├── camera.hpp ├── cone.cpp ├── cone.hpp ├── foxmath.h ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── light.cpp ├── light.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── resource.qrc ├── sphere.cpp └── sphere.hpp ├── 120_Bezier_2D ├── 120_Bezier_2D.pro ├── ShaderSource │ ├── source.frag │ ├── source.geom │ └── source.vert ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui └── resource.qrc ├── 130_Physical_putdown_model ├── 130_Physical_putdown_model.pro ├── Picture │ ├── light.png │ ├── poly_specular_map.png │ ├── poly_tex.png │ ├── wood_box.png │ └── wood_box_specular_map.png ├── ShaderSource │ ├── cube.frag │ ├── cube.vert │ ├── light.frag │ ├── light.vert │ ├── octahedron.frag │ ├── octahedron.geom │ ├── octahedron.vert │ ├── source.frag │ └── source.vert ├── camera.cpp ├── camera.hpp ├── cube.cpp ├── cube.hpp ├── foxmath.h ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── fusiform.cpp ├── fusiform.hpp ├── light.cpp ├── light.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── resource.qrc └── sphere.cpp ├── 135_Physical_roll_model_old_method ├── 135_Physical_roll_model.pro ├── Picture │ ├── light.png │ ├── poly_specular_map.png │ ├── poly_tex.png │ ├── wood_box.png │ └── wood_box_specular_map.png ├── ShaderSource │ ├── cube.frag │ ├── cube.vert │ ├── light.frag │ ├── light.vert │ ├── octahedron.frag │ ├── octahedron.geom │ ├── octahedron.vert │ ├── source.frag │ └── source.vert ├── camera.cpp ├── camera.hpp ├── cube.cpp ├── cube.hpp ├── foxmath.h ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── fusiform.cpp ├── fusiform.hpp ├── light.cpp ├── light.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── resource.qrc └── sphere.cpp ├── 136_Physical_roll_model ├── 136_Physical_roll_model.pro ├── Picture │ ├── light.png │ ├── poly_specular_map.png │ ├── poly_tex.png │ ├── start.png │ ├── wood_box.png │ └── wood_box_specular_map.png ├── ShaderSource │ ├── cube.frag │ ├── cube.vert │ ├── light.frag │ ├── light.vert │ ├── octahedron.frag │ ├── octahedron.geom │ ├── octahedron.vert │ ├── source.frag │ └── source.vert ├── camera.cpp ├── camera.hpp ├── cube.cpp ├── cube.hpp ├── foxmath.hpp ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── light.cpp ├── light.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── octahedron.cpp ├── octahedron.hpp ├── resource.qrc └── sphere.cpp ├── 137_Physical_roll_model_with_SPEED ├── 137_Physical_roll_model_with_SPEED.pro ├── Picture │ ├── light.png │ ├── poly_specular_map.png │ ├── poly_tex.png │ ├── start.png │ ├── wood_box.png │ └── wood_box_specular_map.png ├── ShaderSource │ ├── cube.frag │ ├── cube.vert │ ├── light.frag │ ├── light.vert │ ├── octahedron.frag │ ├── octahedron.geom │ ├── octahedron.vert │ ├── source.frag │ └── source.vert ├── camera.cpp ├── camera.hpp ├── cube.cpp ├── cube.hpp ├── foxmath.hpp ├── foxopenglwidget.cpp ├── foxopenglwidget.h ├── light.cpp ├── light.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── octahedron.cpp ├── octahedron.hpp ├── resource.qrc └── sphere.cpp ├── LICENSE ├── README.md └── doc └── pic ├── README ├── get-7417632.gif ├── get.gif ├── image-20220729182054940.png ├── image-20220808195106987.png ├── image-20220808195151096.png ├── image-20220812134100244.png ├── image-20220812155627459.png ├── image-20220905184211935.png ├── image-20220905184318358.png ├── image-20220905184413706.png ├── image-20220905184728533.png ├── image-20220905184859891.png ├── image-20220905200249305.png ├── image-20220912113006689.png ├── image-20220924215747209.png ├── image-20220924223451296.png ├── image-20220925164252267.png ├── image-20220926130550452.png ├── image-20220926130652221.png ├── image-20221002231151376.png ├── image-20221016125629225.png ├── image-20221017130117822.png ├── image-20221017144440108.png ├── image-20221017155258815.png ├── image-20221017161540264.png ├── image-20221019001455414.png ├── image-20221019005611230.png ├── image-20221101162841805.png ├── wood_box.png └── wood_box_specular_map.png └── 立方体旋转掉落.gif /000 - Apple M1 配置测试/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # 默认忽略的文件 2 | /shelf/ 3 | /workspace.xml 4 | # 基于编辑器的 HTTP 客户端请求 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /000 - Apple M1 配置测试/.idea/.name: -------------------------------------------------------------------------------- 1 | OpenGL -------------------------------------------------------------------------------- /000 - Apple M1 配置测试/.idea/000 - Apple M1 配置测试.iml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /000 - Apple M1 配置测试/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /000 - Apple M1 配置测试/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /000 - Apple M1 配置测试/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /000 - Apple M1 配置测试/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.22) 2 | project(OpenGL) 3 | 4 | set(CMAKE_CXX_STANDARD 11) 5 | 6 | # 包含头文件 7 | include_directories(./glad/include) 8 | 9 | # brew 安装的库都在下面的目录里(M1 版 Mac) /opt/homebrew/Cellar/ 10 | # 把 glfw 加进项目 11 | include_directories(/opt/homebrew/Cellar/glfw/3.3.6/include) 12 | 13 | # glfw 库文件也加进来 14 | link_directories(/opt/homebrew/Cellar/glfw/3.3.6/lib) 15 | 16 | add_executable(OpenGL 17 | ./glad/src/glad.c 18 | main.cpp) 19 | 20 | # 最后把库文件 link 到项目 21 | target_link_libraries( 22 | OpenGL 23 | glfw 24 | ) -------------------------------------------------------------------------------- /001_OpenGLWidget_HelloWidget/001_HelloWidget/axbopenglwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "axbopenglwidget.h" 2 | 3 | AXBOpenGLWidget::AXBOpenGLWidget(QWidget *parent) : QOpenGLWidget(parent) 4 | { 5 | 6 | } 7 | 8 | /* 首要要执行初始化过程,将函数指针指向显卡内的函数 */ 9 | void AXBOpenGLWidget::initializeGL() 10 | { 11 | initializeOpenGLFunctions(); // 【重点】初始化OpenGL函数,将 Qt 里的函数指针指向显卡的函数(头文件 QOpenGLFunctions_X_X_Core) 12 | } 13 | 14 | void AXBOpenGLWidget::resizeGL(int w, int h) 15 | { 16 | 17 | } 18 | 19 | void AXBOpenGLWidget::paintGL() 20 | { 21 | glClearColor(0.2f, 0.3f, 0.32f, 1.0f); // set方法【重点】如果没有 initializeGL,目前是一个空指针状态,没有指向显卡里面的函数,会报错 22 | glClear(GL_COLOR_BUFFER_BIT); // use方法 23 | } 24 | -------------------------------------------------------------------------------- /001_OpenGLWidget_HelloWidget/001_HelloWidget/axbopenglwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef AXBOPENGLWIDGET_H 2 | #define AXBOPENGLWIDGET_H 3 | 4 | #include // 相当于GLFW 5 | #include // 相当于 GLAD 6 | 7 | class AXBOpenGLWidget : public QOpenGLWidget, QOpenGLFunctions_4_5_Core 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit AXBOpenGLWidget(QWidget *parent = nullptr); 12 | 13 | 14 | protected: 15 | /* 需要重载的 QOpenGLWidget 中的三个函数 */ 16 | virtual void initializeGL(); 17 | virtual void resizeGL(int w, int h); 18 | virtual void paintGL(); 19 | 20 | signals: 21 | 22 | public slots: 23 | }; 24 | 25 | #endif // AXBOPENGLWIDGET_H 26 | -------------------------------------------------------------------------------- /001_OpenGLWidget_HelloWidget/001_HelloWidget/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /001_OpenGLWidget_HelloWidget/001_HelloWidget/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | 4 | MainWindow::MainWindow(QWidget *parent) : 5 | QMainWindow(parent), 6 | ui(new Ui::MainWindow) 7 | { 8 | ui->setupUi(this); 9 | setCentralWidget(ui->openGLWidget); // 使OpenGLWidget控件充满整个窗口 10 | } 11 | 12 | MainWindow::~MainWindow() 13 | { 14 | delete ui; 15 | } 16 | -------------------------------------------------------------------------------- /001_OpenGLWidget_HelloWidget/001_HelloWidget/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private: 19 | Ui::MainWindow *ui; 20 | }; 21 | 22 | #endif // MAINWINDOW_H 23 | -------------------------------------------------------------------------------- /002_Triangle_VAO_VBO/002_Triangle_VAO_VBO/axbopenglwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef AXBOPENGLWIDGET_H 2 | #define AXBOPENGLWIDGET_H 3 | 4 | #include // 相当于GLFW 5 | #include // 相当于 GLAD 6 | 7 | class AXBOpenGLWidget : public QOpenGLWidget, QOpenGLFunctions_4_5_Core 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit AXBOpenGLWidget(QWidget *parent = nullptr); 12 | 13 | 14 | protected: 15 | /* 需要重载的 QOpenGLWidget 中的三个函数 */ 16 | virtual void initializeGL(); 17 | virtual void resizeGL(int w, int h); 18 | virtual void paintGL(); 19 | 20 | signals: 21 | 22 | public slots: 23 | }; 24 | 25 | #endif // AXBOPENGLWIDGET_H 26 | -------------------------------------------------------------------------------- /002_Triangle_VAO_VBO/002_Triangle_VAO_VBO/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /002_Triangle_VAO_VBO/002_Triangle_VAO_VBO/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | 4 | MainWindow::MainWindow(QWidget *parent) : 5 | QMainWindow(parent), 6 | ui(new Ui::MainWindow) 7 | { 8 | ui->setupUi(this); 9 | setCentralWidget(ui->openGLWidget); // 使OpenGLWidget控件充满整个窗口 10 | } 11 | 12 | MainWindow::~MainWindow() 13 | { 14 | delete ui; 15 | } 16 | -------------------------------------------------------------------------------- /002_Triangle_VAO_VBO/002_Triangle_VAO_VBO/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private: 19 | Ui::MainWindow *ui; 20 | }; 21 | 22 | #endif // MAINWINDOW_H 23 | -------------------------------------------------------------------------------- /002_Triangle_VAO_VBO_on_M1_Mac/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/002_Triangle_VAO_VBO_on_M1_Mac/.DS_Store -------------------------------------------------------------------------------- /002_Triangle_VAO_VBO_on_M1_Mac/002_Triangle_VAO_VBO/axbopenglwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef AXBOPENGLWIDGET_H 2 | #define AXBOPENGLWIDGET_H 3 | 4 | #include // 相当于GLFW 5 | #include // 相当于 GLAD 6 | 7 | class AXBOpenGLWidget : public QOpenGLWidget, QOpenGLFunctions_3_3_Core 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit AXBOpenGLWidget(QWidget *parent = nullptr); 12 | 13 | 14 | protected: 15 | /* 需要重载的 QOpenGLWidget 中的三个函数 */ 16 | virtual void initializeGL(); 17 | virtual void resizeGL(int w, int h); 18 | virtual void paintGL(); 19 | 20 | signals: 21 | 22 | public slots: 23 | }; 24 | 25 | #endif // AXBOPENGLWIDGET_H 26 | -------------------------------------------------------------------------------- /002_Triangle_VAO_VBO_on_M1_Mac/002_Triangle_VAO_VBO/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | 9 | /** 10 | * 在 M1 的 Mac 要设置这里 11 | * !!3.3 的版本可用,但是 4.5 用不了!,initializeOpenGLFunctions 返回 false 12 | */ 13 | QSurfaceFormat format; 14 | format.setMajorVersion(3); 15 | format.setMinorVersion(3); 16 | format.setProfile(QSurfaceFormat::CoreProfile); 17 | QSurfaceFormat::setDefaultFormat(format); 18 | 19 | 20 | MainWindow w; 21 | w.show(); 22 | 23 | return a.exec(); 24 | } 25 | -------------------------------------------------------------------------------- /002_Triangle_VAO_VBO_on_M1_Mac/002_Triangle_VAO_VBO/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | 4 | MainWindow::MainWindow(QWidget *parent) : 5 | QMainWindow(parent), 6 | ui(new Ui::MainWindow) 7 | { 8 | ui->setupUi(this); 9 | setCentralWidget(ui->openGLWidget); // 使OpenGLWidget控件充满整个窗口 10 | } 11 | 12 | MainWindow::~MainWindow() 13 | { 14 | delete ui; 15 | } 16 | -------------------------------------------------------------------------------- /002_Triangle_VAO_VBO_on_M1_Mac/002_Triangle_VAO_VBO/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private: 19 | Ui::MainWindow *ui; 20 | }; 21 | 22 | #endif // MAINWINDOW_H 23 | -------------------------------------------------------------------------------- /003_Triangle_EBO/foxopenglwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef FOXOPENGLWIDGET_H 2 | #define FOXOPENGLWIDGET_H 3 | 4 | #include // 相当于GLFW 5 | #include // 相当于 GLAD 6 | 7 | class FoxOpenGLWidget : public QOpenGLWidget, QOpenGLFunctions_4_5_Core 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit FoxOpenGLWidget(QWidget *parent = nullptr); 12 | 13 | protected: 14 | /* 需要重载的 QOpenGLWidget 中的三个函数 */ 15 | virtual void initializeGL(); 16 | virtual void resizeGL(int w, int h); 17 | virtual void paintGL(); 18 | 19 | signals: 20 | 21 | public slots: 22 | }; 23 | 24 | #endif // FOXOPENGLWIDGET_H 25 | -------------------------------------------------------------------------------- /003_Triangle_EBO/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /003_Triangle_EBO/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | 4 | MainWindow::MainWindow(QWidget *parent) : 5 | QMainWindow(parent), 6 | ui(new Ui::MainWindow) 7 | { 8 | ui->setupUi(this); 9 | setCentralWidget(ui->openGLWidget); // 将 OpenGL 控件充满整个窗口 10 | } 11 | 12 | MainWindow::~MainWindow() 13 | { 14 | delete ui; 15 | } 16 | -------------------------------------------------------------------------------- /003_Triangle_EBO/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private: 19 | Ui::MainWindow *ui; 20 | }; 21 | 22 | #endif // MAINWINDOW_H 23 | -------------------------------------------------------------------------------- /005_Two_triangle_exercise/axbopenglwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef AXBOPENGLWIDGET_H 2 | #define AXBOPENGLWIDGET_H 3 | 4 | #include // 相当于GLFW 5 | #include // 相当于 GLAD 6 | 7 | class AXBOpenGLWidget : public QOpenGLWidget, QOpenGLFunctions_4_5_Core 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit AXBOpenGLWidget(QWidget *parent = nullptr); 12 | 13 | 14 | protected: 15 | /* 需要重载的 QOpenGLWidget 中的三个函数 */ 16 | virtual void initializeGL(); 17 | virtual void resizeGL(int w, int h); 18 | virtual void paintGL(); 19 | 20 | signals: 21 | 22 | public slots: 23 | }; 24 | 25 | #endif // AXBOPENGLWIDGET_H 26 | -------------------------------------------------------------------------------- /005_Two_triangle_exercise/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | 5 | #if 0 6 | 1. 绘制两个紧挨的三角形 7 | 2. 使用不同的VAO和VBO进行管理 8 | 3. 创建两个着色器程序,右侧的三角形绘制为黄色 9 | #endif 10 | int main(int argc, char *argv[]) 11 | { 12 | QApplication a(argc, argv); 13 | MainWindow w; 14 | w.show(); 15 | 16 | return a.exec(); 17 | } 18 | -------------------------------------------------------------------------------- /005_Two_triangle_exercise/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | 4 | MainWindow::MainWindow(QWidget *parent) : 5 | QMainWindow(parent), 6 | ui(new Ui::MainWindow) 7 | { 8 | ui->setupUi(this); 9 | setCentralWidget(ui->openGLWidget); // 使OpenGLWidget控件充满整个窗口 10 | } 11 | 12 | MainWindow::~MainWindow() 13 | { 14 | delete ui; 15 | } 16 | -------------------------------------------------------------------------------- /005_Two_triangle_exercise/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private: 19 | Ui::MainWindow *ui; 20 | }; 21 | 22 | #endif // MAINWINDOW_H 23 | -------------------------------------------------------------------------------- /010_Qt_UI_with_OpenGL/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /010_Qt_UI_with_OpenGL/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void on_actionDrawRect_triggered(); 20 | 21 | void on_actionWireframe_triggered(); 22 | 23 | void on_actionClear_triggered(); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | }; 28 | 29 | #endif // MAINWINDOW_H 30 | -------------------------------------------------------------------------------- /011_QOpenGLShaderProgram/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | void main() 5 | { 6 | FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f); 7 | } 8 | -------------------------------------------------------------------------------- /011_QOpenGLShaderProgram/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; 3 | 4 | void main() 5 | { 6 | gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0f); 7 | } 8 | -------------------------------------------------------------------------------- /011_QOpenGLShaderProgram/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /011_QOpenGLShaderProgram/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void on_actionDrawRect_triggered(); 20 | 21 | void on_actionWireframe_triggered(); 22 | 23 | void on_actionClear_triggered(); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | }; 28 | 29 | #endif // MAINWINDOW_H 30 | -------------------------------------------------------------------------------- /011_QOpenGLShaderProgram/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/source.frag 4 | ShaderSource/source.vert 5 | 6 | 7 | -------------------------------------------------------------------------------- /020_GLSL_in_out/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | in vec4 vertexColor; 4 | 5 | void main() 6 | { 7 | // FragColor = vertexColor; 8 | FragColor = vec4(vertexColor.yyz, 1.0); 9 | } 10 | -------------------------------------------------------------------------------- /020_GLSL_in_out/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; 3 | out vec4 vertexColor; 4 | 5 | void main() 6 | { 7 | gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0f); 8 | vertexColor = vec4(0.5, 1.0, 0.0, 1.0); 9 | } 10 | -------------------------------------------------------------------------------- /020_GLSL_in_out/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /020_GLSL_in_out/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void on_actionDrawRect_triggered(); 20 | 21 | void on_actionWireframe_triggered(); 22 | 23 | void on_actionClear_triggered(); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | }; 28 | 29 | #endif // MAINWINDOW_H 30 | -------------------------------------------------------------------------------- /020_GLSL_in_out/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/source.frag 4 | ShaderSource/source.vert 5 | 6 | 7 | -------------------------------------------------------------------------------- /021_GLSL_layout/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | in vec4 vertexColor; 4 | 5 | void main() 6 | { 7 | // FragColor = vertexColor; 8 | FragColor = vec4(vertexColor.yyz, 1.0); 9 | } 10 | -------------------------------------------------------------------------------- /021_GLSL_layout/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 2) in vec3 aPos; 3 | out vec4 vertexColor; 4 | 5 | void main() 6 | { 7 | gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0f); 8 | vertexColor = vec4(0.5, 1.0, 0.0, 1.0); 9 | } 10 | -------------------------------------------------------------------------------- /021_GLSL_layout/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /021_GLSL_layout/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void on_actionDrawRect_triggered(); 20 | 21 | void on_actionWireframe_triggered(); 22 | 23 | void on_actionClear_triggered(); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | }; 28 | 29 | #endif // MAINWINDOW_H 30 | -------------------------------------------------------------------------------- /021_GLSL_layout/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/source.frag 4 | ShaderSource/source.vert 5 | 6 | 7 | -------------------------------------------------------------------------------- /022_GLSL_uniform/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | in vec4 vertexColor; 4 | 5 | uniform vec4 ourColor; 6 | 7 | void main() 8 | { 9 | FragColor = ourColor; 10 | } 11 | -------------------------------------------------------------------------------- /022_GLSL_uniform/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 2) in vec3 aPos; 3 | out vec4 vertexColor; 4 | 5 | void main() 6 | { 7 | gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0f); 8 | vertexColor = vec4(0.5, 1.0, 0.0, 1.0); 9 | } 10 | -------------------------------------------------------------------------------- /022_GLSL_uniform/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /022_GLSL_uniform/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void on_actionDrawRect_triggered(); 20 | 21 | void on_actionWireframe_triggered(); 22 | 23 | void on_actionClear_triggered(); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | }; 28 | 29 | #endif // MAINWINDOW_H 30 | -------------------------------------------------------------------------------- /022_GLSL_uniform/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/source.frag 4 | ShaderSource/source.vert 5 | 6 | 7 | -------------------------------------------------------------------------------- /023_GLSL_more_Attrib/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | in vec3 ourColor; 4 | 5 | void main() 6 | { 7 | FragColor = vec4(ourColor, 1.0); 8 | } 9 | -------------------------------------------------------------------------------- /023_GLSL_more_Attrib/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | layout (location = 1) in vec3 aColor; // 颜色变量的属性位置值为 1 4 | 5 | out vec3 ourColor; // 向片段着色器输出一个颜色 6 | 7 | void main() 8 | { 9 | gl_Position = vec4(aPos, 1.0); 10 | ourColor = aColor; // 将ourColor设置为我们从顶点数据那里得到的输入颜色 11 | } 12 | -------------------------------------------------------------------------------- /023_GLSL_more_Attrib/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /023_GLSL_more_Attrib/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void on_actionDrawRect_triggered(); 20 | 21 | void on_actionWireframe_triggered(); 22 | 23 | void on_actionClear_triggered(); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | }; 28 | 29 | #endif // MAINWINDOW_H 30 | -------------------------------------------------------------------------------- /023_GLSL_more_Attrib/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/source.frag 4 | ShaderSource/source.vert 5 | 6 | 7 | -------------------------------------------------------------------------------- /024_GLSL_exercise/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | in vec3 ourColor; 4 | 5 | void main() 6 | { 7 | FragColor = vec4(ourColor, 1.0); 8 | } 9 | -------------------------------------------------------------------------------- /024_GLSL_exercise/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | layout (location = 1) in vec3 aColor; // 颜色变量的属性位置值为 1 4 | 5 | out vec3 ourColor; // 向片段着色器输出一个颜色 6 | 7 | uniform float xOffset; 8 | 9 | void main() 10 | { 11 | gl_Position = vec4(aPos.x + xOffset, aPos.y * -1, aPos.z, 1.0); 12 | ourColor = aColor; // 将ourColor设置为我们从顶点数据那里得到的输入颜色 13 | } 14 | -------------------------------------------------------------------------------- /024_GLSL_exercise/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | #if 0 5 | 6 | 1. 修改顶点着色器让三角形上下颠倒 7 | 2. 使用 uniform 定义一个水平偏移量,在顶点着色器中使用这个偏移量将三角形移动到屏幕右侧 8 | 9 | #endif 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | QApplication a(argc, argv); 14 | MainWindow w; 15 | w.show(); 16 | 17 | return a.exec(); 18 | } 19 | -------------------------------------------------------------------------------- /024_GLSL_exercise/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void on_actionDrawRect_triggered(); 20 | 21 | void on_actionWireframe_triggered(); 22 | 23 | void on_actionClear_triggered(); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | }; 28 | 29 | #endif // MAINWINDOW_H 30 | -------------------------------------------------------------------------------- /024_GLSL_exercise/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/source.frag 4 | ShaderSource/source.vert 5 | 6 | 7 | -------------------------------------------------------------------------------- /030_Texel/Pictures/nekosilverfox.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/030_Texel/Pictures/nekosilverfox.jpg -------------------------------------------------------------------------------- /030_Texel/Pictures/wall.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/030_Texel/Pictures/wall.jpg -------------------------------------------------------------------------------- /030_Texel/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | in vec3 ourColor; 5 | in vec2 ourTexel; 6 | 7 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 8 | uniform sampler2D texture0; 9 | uniform sampler2D texture1; 10 | 11 | void main() 12 | { 13 | // FragColor = vec4(ourColor, 1.0); 14 | // FragColor = texture(texture0, ourTexel) * vec4(0.5, 0.7, 0.0, 0.2); // 可以使用乘法改变颜色 15 | FragColor = mix(texture(texture0, ourTexel), 16 | texture(texture1, ourTexel), 17 | 0.5); 18 | } 19 | -------------------------------------------------------------------------------- /030_Texel/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | layout (location = 1) in vec3 aColor; // 颜色变量的属性位置值为 1 4 | layout (location = 2) in vec2 aTexel; // 存储2D纹理坐标s、t 5 | 6 | out vec3 ourColor; // 向片段着色器输出一个颜色 7 | out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 8 | 9 | void main() 10 | { 11 | gl_Position = vec4(aPos, 1.0); 12 | ourColor = aColor; // 将ourColor设置为我们从顶点数据那里得到的输入颜色 13 | ourTexel = aTexel; 14 | } 15 | -------------------------------------------------------------------------------- /030_Texel/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /030_Texel/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void on_actionDrawRect_triggered(); 20 | 21 | void on_actionWireframe_triggered(); 22 | 23 | void on_actionClear_triggered(); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | }; 28 | 29 | #endif // MAINWINDOW_H 30 | -------------------------------------------------------------------------------- /030_Texel/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/source.frag 4 | ShaderSource/source.vert 5 | 6 | 7 | Pictures/wall.jpg 8 | Pictures/nekosilverfox.jpg 9 | 10 | 11 | -------------------------------------------------------------------------------- /031_Texel_wrap/Pictures/nekosilverfox.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/031_Texel_wrap/Pictures/nekosilverfox.jpg -------------------------------------------------------------------------------- /031_Texel_wrap/Pictures/nekosilverfox_bk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/031_Texel_wrap/Pictures/nekosilverfox_bk.jpg -------------------------------------------------------------------------------- /031_Texel_wrap/Pictures/wall.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/031_Texel_wrap/Pictures/wall.jpg -------------------------------------------------------------------------------- /031_Texel_wrap/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | in vec3 ourColor; 5 | in vec2 ourTexel; 6 | 7 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 8 | uniform sampler2D texture0; 9 | uniform sampler2D texture1; 10 | uniform sampler2D texture2; 11 | 12 | void main() 13 | { 14 | // FragColor = vec4(ourColor, 1.0); 15 | // FragColor = texture(texture0, ourTexel) * vec4(0.5, 0.7, 0.0, 0.2); // 可以使用乘法改变颜色 16 | // FragColor = mix(texture(texture0, ourTexel), 17 | // texture(texture1, ourTexel), 18 | // 0.5); 19 | FragColor = texture(texture2, ourTexel); 20 | } 21 | -------------------------------------------------------------------------------- /031_Texel_wrap/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | layout (location = 1) in vec3 aColor; // 颜色变量的属性位置值为 1 4 | layout (location = 2) in vec2 aTexel; // 存储2D纹理坐标s、t 5 | 6 | out vec3 ourColor; // 向片段着色器输出一个颜色 7 | out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 8 | 9 | void main() 10 | { 11 | gl_Position = vec4(aPos, 1.0); 12 | ourColor = aColor; // 将ourColor设置为我们从顶点数据那里得到的输入颜色 13 | ourTexel = aTexel; 14 | } 15 | -------------------------------------------------------------------------------- /031_Texel_wrap/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /031_Texel_wrap/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void on_actionDrawRect_triggered(); 20 | 21 | void on_actionWireframe_triggered(); 22 | 23 | void on_actionClear_triggered(); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | }; 28 | 29 | #endif // MAINWINDOW_H 30 | -------------------------------------------------------------------------------- /031_Texel_wrap/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/source.frag 4 | ShaderSource/source.vert 5 | 6 | 7 | Pictures/wall.jpg 8 | Pictures/nekosilverfox.jpg 9 | Pictures/nekosilverfox_bk.jpg 10 | 11 | 12 | -------------------------------------------------------------------------------- /032_Texture_Filtering/Pictures/nekosilverfox.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/032_Texture_Filtering/Pictures/nekosilverfox.jpg -------------------------------------------------------------------------------- /032_Texture_Filtering/Pictures/nekosilverfox_bk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/032_Texture_Filtering/Pictures/nekosilverfox_bk.jpg -------------------------------------------------------------------------------- /032_Texture_Filtering/Pictures/wall.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/032_Texture_Filtering/Pictures/wall.jpg -------------------------------------------------------------------------------- /032_Texture_Filtering/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | in vec3 ourColor; 5 | in vec2 ourTexel; 6 | 7 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 8 | uniform sampler2D texture0; 9 | uniform sampler2D texture1; 10 | uniform sampler2D texture2; 11 | 12 | void main() 13 | { 14 | // FragColor = vec4(ourColor, 1.0); 15 | // FragColor = texture(texture0, ourTexel) * vec4(0.5, 0.7, 0.0, 0.2); // 可以使用乘法改变颜色 16 | // FragColor = mix(texture(texture0, ourTexel), 17 | // texture(texture1, ourTexel), 18 | // 0.5); 19 | FragColor = texture(texture2, ourTexel); 20 | } 21 | -------------------------------------------------------------------------------- /032_Texture_Filtering/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | layout (location = 1) in vec3 aColor; // 颜色变量的属性位置值为 1 4 | layout (location = 2) in vec2 aTexel; // 存储2D纹理坐标s、t 5 | 6 | out vec3 ourColor; // 向片段着色器输出一个颜色 7 | out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 8 | 9 | void main() 10 | { 11 | gl_Position = vec4(aPos, 1.0); 12 | ourColor = aColor; // 将ourColor设置为我们从顶点数据那里得到的输入颜色 13 | ourTexel = aTexel; 14 | } 15 | -------------------------------------------------------------------------------- /032_Texture_Filtering/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /032_Texture_Filtering/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void on_actionDrawRect_triggered(); 20 | 21 | void on_actionWireframe_triggered(); 22 | 23 | void on_actionClear_triggered(); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | }; 28 | 29 | #endif // MAINWINDOW_H 30 | -------------------------------------------------------------------------------- /032_Texture_Filtering/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/source.frag 4 | ShaderSource/source.vert 5 | 6 | 7 | Pictures/wall.jpg 8 | Pictures/nekosilverfox.jpg 9 | Pictures/nekosilverfox_bk.jpg 10 | 11 | 12 | -------------------------------------------------------------------------------- /033_Texture_exercise/Pictures/nekosilverfox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/033_Texture_exercise/Pictures/nekosilverfox.png -------------------------------------------------------------------------------- /033_Texture_exercise/Pictures/nekosilverfox_bk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/033_Texture_exercise/Pictures/nekosilverfox_bk.jpg -------------------------------------------------------------------------------- /033_Texture_exercise/Pictures/wall.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/033_Texture_exercise/Pictures/wall.jpg -------------------------------------------------------------------------------- /033_Texture_exercise/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | layout (location = 1) in vec3 aColor; // 颜色变量的属性位置值为 1 4 | layout (location = 2) in vec2 aTexel; // 存储2D纹理坐标s、t 5 | 6 | out vec3 ourColor; // 向片段着色器输出一个颜色 7 | out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 8 | 9 | void main() 10 | { 11 | gl_Position = vec4(aPos, 1.0); 12 | ourColor = aColor; // 将ourColor设置为我们从顶点数据那里得到的输入颜色 13 | ourTexel = vec2(aTexel.s * -1, aTexel.t); 14 | } 15 | -------------------------------------------------------------------------------- /033_Texture_exercise/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | #if 0 5 | 6 | 1. 修改片段着色器,使雪狸图案朝另一个方向看 7 | 2. 尝试不同的纹理环绕方式,设定一个从 0.0f 到 2.0f 范围内的(而不是原来的0.0f 到 1.0f)纹理坐标。试试看能不能放置4个 8 | 3. 尝试在矩形上只显示纹理图像中间的第一部分,修改纹理坐标,达到刚好能看见单个像素的效果。尝试使用 GL_NEAREST 的纹理过滤方式让像素现实的更加清晰 9 | 4. 使用一个 uniform变量作为mix函数的第三个参数来改变两个纹理的可见度,使用上下键来改变箱子或者笑脸的可见度 10 | 11 | #endif 12 | 13 | 14 | int main(int argc, char *argv[]) 15 | { 16 | QApplication a(argc, argv); 17 | MainWindow w; 18 | w.show(); 19 | 20 | return a.exec(); 21 | } 22 | -------------------------------------------------------------------------------- /033_Texture_exercise/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void on_actionDrawRect_triggered(); 20 | 21 | void on_actionWireframe_triggered(); 22 | 23 | void on_actionClear_triggered(); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | }; 28 | 29 | #endif // MAINWINDOW_H 30 | -------------------------------------------------------------------------------- /033_Texture_exercise/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/source.frag 4 | ShaderSource/source.vert 5 | 6 | 7 | Pictures/wall.jpg 8 | Pictures/nekosilverfox_bk.jpg 9 | Pictures/nekosilverfox.png 10 | 11 | 12 | -------------------------------------------------------------------------------- /040_Rotate_and_Move/Pictures/nekosilverfox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/040_Rotate_and_Move/Pictures/nekosilverfox.png -------------------------------------------------------------------------------- /040_Rotate_and_Move/Pictures/nekosilverfox_bk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/040_Rotate_and_Move/Pictures/nekosilverfox_bk.jpg -------------------------------------------------------------------------------- /040_Rotate_and_Move/Pictures/wall.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/040_Rotate_and_Move/Pictures/wall.jpg -------------------------------------------------------------------------------- /040_Rotate_and_Move/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | layout (location = 1) in vec3 aColor; // 颜色变量的属性位置值为 1 4 | layout (location = 2) in vec2 aTexel; // 存储2D纹理坐标s、t 5 | 6 | out vec3 ourColor; // 向片段着色器输出一个颜色 7 | out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 8 | 9 | uniform mat4 matrix; 10 | 11 | void main() 12 | { 13 | gl_Position = matrix * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果 14 | ourColor = aColor; // 将ourColor设置为我们从顶点数据那里得到的输入颜色 15 | ourTexel = vec2(aTexel.s * -1, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /040_Rotate_and_Move/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /040_Rotate_and_Move/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void on_actionDrawRect_triggered(); 20 | 21 | void on_actionWireframe_triggered(); 22 | 23 | void on_actionClear_triggered(); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | }; 28 | 29 | #endif // MAINWINDOW_H 30 | -------------------------------------------------------------------------------- /040_Rotate_and_Move/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/source.frag 4 | ShaderSource/source.vert 5 | 6 | 7 | Pictures/wall.jpg 8 | Pictures/nekosilverfox_bk.jpg 9 | Pictures/nekosilverfox.png 10 | 11 | 12 | -------------------------------------------------------------------------------- /045_3D/Pictures/nekosilverfox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/045_3D/Pictures/nekosilverfox.png -------------------------------------------------------------------------------- /045_3D/Pictures/nekosilverfox_bk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/045_3D/Pictures/nekosilverfox_bk.jpg -------------------------------------------------------------------------------- /045_3D/Pictures/wall.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/045_3D/Pictures/wall.jpg -------------------------------------------------------------------------------- /045_3D/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | uniform sampler2D texture0; 8 | uniform sampler2D texture1; 9 | uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | FragColor = mix(texture(texture0, ourTexel), 16 | texture(texture1, ourTexel), val_alpha); 17 | } 18 | -------------------------------------------------------------------------------- /045_3D/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /045_3D/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /045_3D/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void on_actionDrawRect_triggered(); 20 | 21 | void on_actionWireframe_triggered(); 22 | 23 | void on_actionClear_triggered(); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | }; 28 | 29 | #endif // MAINWINDOW_H 30 | -------------------------------------------------------------------------------- /045_3D/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/source.frag 4 | ShaderSource/source.vert 5 | 6 | 7 | Pictures/wall.jpg 8 | Pictures/nekosilverfox_bk.jpg 9 | Pictures/nekosilverfox.png 10 | 11 | 12 | -------------------------------------------------------------------------------- /046_3D_exercise/Pictures/nekosilverfox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/046_3D_exercise/Pictures/nekosilverfox.png -------------------------------------------------------------------------------- /046_3D_exercise/Pictures/nekosilverfox_bk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/046_3D_exercise/Pictures/nekosilverfox_bk.jpg -------------------------------------------------------------------------------- /046_3D_exercise/Pictures/wall.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/046_3D_exercise/Pictures/wall.jpg -------------------------------------------------------------------------------- /046_3D_exercise/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | uniform sampler2D texture0; 8 | uniform sampler2D texture1; 9 | uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | FragColor = mix(texture(texture0, ourTexel), 16 | texture(texture1, ourTexel), val_alpha); 17 | } 18 | -------------------------------------------------------------------------------- /046_3D_exercise/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /046_3D_exercise/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | #if 0 5 | 1. 对透视投影中的 Fov 和 ratio 参数进行试验。看能能否搞懂他们是如何影响平截头体的 6 | 2. 将观察矩阵在各个方向上进行位移,看看场景是如何改变的。注意把观察矩阵当成摄像机对象 7 | 3. 使用模型矩阵只让是3的倍数的箱子旋转(以及第一个箱子),而让剩下的箱子保持静止 8 | #endif 9 | 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | QApplication a(argc, argv); 14 | MainWindow w; 15 | w.show(); 16 | 17 | return a.exec(); 18 | } 19 | -------------------------------------------------------------------------------- /046_3D_exercise/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void on_actionDrawRect_triggered(); 20 | 21 | void on_actionWireframe_triggered(); 22 | 23 | void on_actionClear_triggered(); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | }; 28 | 29 | #endif // MAINWINDOW_H 30 | -------------------------------------------------------------------------------- /046_3D_exercise/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/source.frag 4 | ShaderSource/source.vert 5 | 6 | 7 | Pictures/wall.jpg 8 | Pictures/nekosilverfox_bk.jpg 9 | Pictures/nekosilverfox.png 10 | 11 | 12 | -------------------------------------------------------------------------------- /047_3D_Camera/Pictures/nekosilverfox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/047_3D_Camera/Pictures/nekosilverfox.png -------------------------------------------------------------------------------- /047_3D_Camera/Pictures/nekosilverfox_bk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/047_3D_Camera/Pictures/nekosilverfox_bk.jpg -------------------------------------------------------------------------------- /047_3D_Camera/Pictures/wall.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/047_3D_Camera/Pictures/wall.jpg -------------------------------------------------------------------------------- /047_3D_Camera/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | uniform sampler2D texture0; 8 | uniform sampler2D texture1; 9 | uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | FragColor = mix(texture(texture0, ourTexel), 16 | texture(texture1, ourTexel), val_alpha); 17 | } 18 | -------------------------------------------------------------------------------- /047_3D_Camera/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /047_3D_Camera/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | #if 0 5 | 1. 对透视投影中的 Fov 和 ratio 参数进行试验。看能能否搞懂他们是如何影响平截头体的 6 | 2. 将观察矩阵在各个方向上进行位移,看看场景是如何改变的。注意把观察矩阵当成摄像机对象 7 | 3. 使用模型矩阵只让是3的倍数的箱子旋转(以及第一个箱子),而让剩下的箱子保持静止 8 | #endif 9 | 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | QApplication a(argc, argv); 14 | MainWindow w; 15 | w.show(); 16 | 17 | return a.exec(); 18 | } 19 | -------------------------------------------------------------------------------- /047_3D_Camera/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void on_actionDrawRect_triggered(); 20 | 21 | void on_actionWireframe_triggered(); 22 | 23 | void on_actionClear_triggered(); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | }; 28 | 29 | #endif // MAINWINDOW_H 30 | -------------------------------------------------------------------------------- /047_3D_Camera/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/source.frag 4 | ShaderSource/source.vert 5 | 6 | 7 | Pictures/wall.jpg 8 | Pictures/nekosilverfox_bk.jpg 9 | Pictures/nekosilverfox.png 10 | 11 | 12 | -------------------------------------------------------------------------------- /048_3D_Move_camera/Pictures/nekosilverfox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/048_3D_Move_camera/Pictures/nekosilverfox.png -------------------------------------------------------------------------------- /048_3D_Move_camera/Pictures/nekosilverfox_bk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/048_3D_Move_camera/Pictures/nekosilverfox_bk.jpg -------------------------------------------------------------------------------- /048_3D_Move_camera/Pictures/wall.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/048_3D_Move_camera/Pictures/wall.jpg -------------------------------------------------------------------------------- /048_3D_Move_camera/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | uniform sampler2D texture0; 8 | uniform sampler2D texture1; 9 | uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | FragColor = mix(texture(texture0, ourTexel), 16 | texture(texture1, ourTexel), val_alpha); 17 | } 18 | -------------------------------------------------------------------------------- /048_3D_Move_camera/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /048_3D_Move_camera/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | #if 0 5 | 1. 对透视投影中的 Fov 和 ratio 参数进行试验。看能能否搞懂他们是如何影响平截头体的 6 | 2. 将观察矩阵在各个方向上进行位移,看看场景是如何改变的。注意把观察矩阵当成摄像机对象 7 | 3. 使用模型矩阵只让是3的倍数的箱子旋转(以及第一个箱子),而让剩下的箱子保持静止 8 | #endif 9 | 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | QApplication a(argc, argv); 14 | MainWindow w; 15 | w.show(); 16 | 17 | return a.exec(); 18 | } 19 | -------------------------------------------------------------------------------- /048_3D_Move_camera/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void on_actionDrawRect_triggered(); 20 | 21 | void on_actionWireframe_triggered(); 22 | 23 | void on_actionClear_triggered(); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | }; 28 | 29 | #endif // MAINWINDOW_H 30 | -------------------------------------------------------------------------------- /048_3D_Move_camera/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/source.frag 4 | ShaderSource/source.vert 5 | 6 | 7 | Pictures/wall.jpg 8 | Pictures/nekosilverfox_bk.jpg 9 | Pictures/nekosilverfox.png 10 | 11 | 12 | -------------------------------------------------------------------------------- /049_Camera_OOP/Pictures/nekosilverfox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/049_Camera_OOP/Pictures/nekosilverfox.png -------------------------------------------------------------------------------- /049_Camera_OOP/Pictures/nekosilverfox_bk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/049_Camera_OOP/Pictures/nekosilverfox_bk.jpg -------------------------------------------------------------------------------- /049_Camera_OOP/Pictures/wall.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/049_Camera_OOP/Pictures/wall.jpg -------------------------------------------------------------------------------- /049_Camera_OOP/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | uniform sampler2D texture0; 8 | uniform sampler2D texture1; 9 | uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | FragColor = mix(texture(texture0, ourTexel), 16 | texture(texture1, ourTexel), val_alpha); 17 | } 18 | -------------------------------------------------------------------------------- /049_Camera_OOP/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /049_Camera_OOP/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | #if 0 5 | 1. 对透视投影中的 Fov 和 ratio 参数进行试验。看能能否搞懂他们是如何影响平截头体的 6 | 2. 将观察矩阵在各个方向上进行位移,看看场景是如何改变的。注意把观察矩阵当成摄像机对象 7 | 3. 使用模型矩阵只让是3的倍数的箱子旋转(以及第一个箱子),而让剩下的箱子保持静止 8 | #endif 9 | 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | QApplication a(argc, argv); 14 | MainWindow w; 15 | w.show(); 16 | 17 | return a.exec(); 18 | } 19 | -------------------------------------------------------------------------------- /049_Camera_OOP/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void on_actionDrawRect_triggered(); 20 | 21 | void on_actionWireframe_triggered(); 22 | 23 | void on_actionClear_triggered(); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | }; 28 | 29 | #endif // MAINWINDOW_H 30 | -------------------------------------------------------------------------------- /049_Camera_OOP/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/source.frag 4 | ShaderSource/source.vert 5 | 6 | 7 | Pictures/wall.jpg 8 | Pictures/nekosilverfox_bk.jpg 9 | Pictures/nekosilverfox.png 10 | 11 | 12 | -------------------------------------------------------------------------------- /055_3D_Sphere/Pictures/nekosilverfox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/055_3D_Sphere/Pictures/nekosilverfox.png -------------------------------------------------------------------------------- /055_3D_Sphere/Pictures/nekosilverfox_bk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/055_3D_Sphere/Pictures/nekosilverfox_bk.jpg -------------------------------------------------------------------------------- /055_3D_Sphere/Pictures/wall.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/055_3D_Sphere/Pictures/wall.jpg -------------------------------------------------------------------------------- /055_3D_Sphere/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | //in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | //uniform sampler2D texture0; 8 | //uniform sampler2D texture1; 9 | //uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | // FragColor = mix(texture(texture0, ourTexel), 16 | // texture(texture1, ourTexel), val_alpha); 17 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 18 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 19 | val_alpha); 20 | } 21 | -------------------------------------------------------------------------------- /055_3D_Sphere/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | //layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | //out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | // ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /055_3D_Sphere/ShaderSource/sphere.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform float val_alpha; 5 | 6 | void main() 7 | { 8 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 9 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 10 | val_alpha); 11 | } 12 | -------------------------------------------------------------------------------- /055_3D_Sphere/ShaderSource/sphere.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /055_3D_Sphere/cube.cpp: -------------------------------------------------------------------------------- 1 | #include "cube.h" 2 | 3 | Cube::Cube() 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /055_3D_Sphere/cube.h: -------------------------------------------------------------------------------- 1 | #ifndef CUBE_H 2 | #define CUBE_H 3 | 4 | 5 | class Cube 6 | { 7 | public: 8 | Cube(); 9 | }; 10 | 11 | #endif // CUBE_H -------------------------------------------------------------------------------- /055_3D_Sphere/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | #if 0 5 | 1. 对透视投影中的 Fov 和 ratio 参数进行试验。看能能否搞懂他们是如何影响平截头体的 6 | 2. 将观察矩阵在各个方向上进行位移,看看场景是如何改变的。注意把观察矩阵当成摄像机对象 7 | 3. 使用模型矩阵只让是3的倍数的箱子旋转(以及第一个箱子),而让剩下的箱子保持静止 8 | #endif 9 | 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | QApplication a(argc, argv); 14 | MainWindow w; 15 | w.show(); 16 | 17 | return a.exec(); 18 | } 19 | -------------------------------------------------------------------------------- /055_3D_Sphere/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void on_actionDrawRect_triggered(); 20 | 21 | void on_actionWireframe_triggered(); 22 | 23 | void on_actionClear_triggered(); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | }; 28 | 29 | #endif // MAINWINDOW_H 30 | -------------------------------------------------------------------------------- /055_3D_Sphere/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/source.frag 4 | ShaderSource/source.vert 5 | ShaderSource/sphere.frag 6 | ShaderSource/sphere.vert 7 | 8 | 9 | Pictures/wall.jpg 10 | Pictures/nekosilverfox_bk.jpg 11 | Pictures/nekosilverfox.png 12 | 13 | 14 | -------------------------------------------------------------------------------- /056_3D_Sphere_and_Cube/ShaderSource/cube.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | //in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | //uniform sampler2D texture0; 8 | //uniform sampler2D texture1; 9 | //uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | // FragColor = mix(texture(texture0, ourTexel), 16 | // texture(texture1, ourTexel), val_alpha); 17 | FragColor = mix(vec4(0.0f, 1.0f, 0.0f, 1.0f), 18 | vec4(0.0f, 0.0f, 1.0f, 1.0f), 19 | val_alpha); 20 | } 21 | -------------------------------------------------------------------------------- /056_3D_Sphere_and_Cube/ShaderSource/cube.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | //layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | //out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | // ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /056_3D_Sphere_and_Cube/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | //in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | //uniform sampler2D texture0; 8 | //uniform sampler2D texture1; 9 | //uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | // FragColor = mix(texture(texture0, ourTexel), 16 | // texture(texture1, ourTexel), val_alpha); 17 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 18 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 19 | val_alpha); 20 | } 21 | -------------------------------------------------------------------------------- /056_3D_Sphere_and_Cube/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | //layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | //out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | // ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /056_3D_Sphere_and_Cube/ShaderSource/sphere.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform float val_alpha; 5 | 6 | void main() 7 | { 8 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 9 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 10 | val_alpha); 11 | } 12 | -------------------------------------------------------------------------------- /056_3D_Sphere_and_Cube/ShaderSource/sphere.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /056_3D_Sphere_and_Cube/cube.h: -------------------------------------------------------------------------------- 1 | #ifndef CUBE_H 2 | #define CUBE_H 3 | 4 | 5 | #include 6 | 7 | 8 | const float LENGTH = 1.0f; 9 | 10 | 11 | class Cube 12 | { 13 | public: 14 | Cube(); 15 | Cube(const float length); 16 | 17 | private: 18 | void _genVectorVerticesAndIndices(); 19 | 20 | public: 21 | std::vector vertices; // 顶点 22 | 23 | private: 24 | float _length; 25 | }; 26 | 27 | #endif // CUBE_H 28 | -------------------------------------------------------------------------------- /056_3D_Sphere_and_Cube/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | #if 0 5 | 1. 对透视投影中的 Fov 和 ratio 参数进行试验。看能能否搞懂他们是如何影响平截头体的 6 | 2. 将观察矩阵在各个方向上进行位移,看看场景是如何改变的。注意把观察矩阵当成摄像机对象 7 | 3. 使用模型矩阵只让是3的倍数的箱子旋转(以及第一个箱子),而让剩下的箱子保持静止 8 | #endif 9 | 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | QApplication a(argc, argv); 14 | MainWindow w; 15 | w.show(); 16 | 17 | return a.exec(); 18 | } 19 | -------------------------------------------------------------------------------- /056_3D_Sphere_and_Cube/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void on_actionDrawRect_triggered(); 20 | 21 | void on_actionWireframe_triggered(); 22 | 23 | void on_actionClear_triggered(); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | }; 28 | 29 | #endif // MAINWINDOW_H 30 | -------------------------------------------------------------------------------- /056_3D_Sphere_and_Cube/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/sphere.frag 4 | ShaderSource/sphere.vert 5 | ShaderSource/cube.frag 6 | ShaderSource/cube.vert 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /057_3D_Sphere_Cube_Cone/ShaderSource/cone.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform float val_alpha; 5 | 6 | void main() 7 | { 8 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 9 | vec4(0.0f, 0.0f, 1.0f, 1.0f), 10 | val_alpha); 11 | } 12 | -------------------------------------------------------------------------------- /057_3D_Sphere_Cube_Cone/ShaderSource/cone.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /057_3D_Sphere_Cube_Cone/ShaderSource/cube.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | //in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | //uniform sampler2D texture0; 8 | //uniform sampler2D texture1; 9 | //uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | // FragColor = mix(texture(texture0, ourTexel), 16 | // texture(texture1, ourTexel), val_alpha); 17 | FragColor = mix(vec4(0.0f, 1.0f, 0.0f, 1.0f), 18 | vec4(0.0f, 0.0f, 1.0f, 1.0f), 19 | val_alpha); 20 | } 21 | -------------------------------------------------------------------------------- /057_3D_Sphere_Cube_Cone/ShaderSource/cube.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | //layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | //out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | // ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /057_3D_Sphere_Cube_Cone/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | //in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | //uniform sampler2D texture0; 8 | //uniform sampler2D texture1; 9 | //uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | // FragColor = mix(texture(texture0, ourTexel), 16 | // texture(texture1, ourTexel), val_alpha); 17 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 18 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 19 | val_alpha); 20 | } 21 | -------------------------------------------------------------------------------- /057_3D_Sphere_Cube_Cone/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | //layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | //out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | // ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /057_3D_Sphere_Cube_Cone/ShaderSource/sphere.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform float val_alpha; 5 | 6 | void main() 7 | { 8 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 9 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 10 | val_alpha); 11 | } 12 | -------------------------------------------------------------------------------- /057_3D_Sphere_Cube_Cone/ShaderSource/sphere.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /057_3D_Sphere_Cube_Cone/cube.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CUBE_H 2 | #define CUBE_H 3 | 4 | 5 | #include 6 | #include 7 | 8 | const float LENGTH = 1.0f; 9 | 10 | 11 | class Cube 12 | { 13 | public: 14 | Cube(); 15 | Cube(const float length); 16 | 17 | private: 18 | void _genVectorVerticesAndIndices(); 19 | 20 | public: 21 | std::vector vertices; // 顶点 22 | 23 | QMatrix4x4 mat_model; 24 | 25 | private: 26 | float _length; 27 | }; 28 | 29 | #endif // CUBE_H 30 | -------------------------------------------------------------------------------- /057_3D_Sphere_Cube_Cone/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /057_3D_Sphere_Cube_Cone/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/sphere.frag 4 | ShaderSource/sphere.vert 5 | ShaderSource/cube.frag 6 | ShaderSource/cube.vert 7 | ShaderSource/cone.frag 8 | ShaderSource/cone.vert 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /057_3D_Sphere_Cube_Cone_AppleSoc/ShaderSource/cone.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform float val_alpha; 5 | 6 | void main() 7 | { 8 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 9 | vec4(0.0f, 0.0f, 1.0f, 1.0f), 10 | val_alpha); 11 | } 12 | -------------------------------------------------------------------------------- /057_3D_Sphere_Cube_Cone_AppleSoc/ShaderSource/cone.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /057_3D_Sphere_Cube_Cone_AppleSoc/ShaderSource/cube.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | //in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | //uniform sampler2D texture0; 8 | //uniform sampler2D texture1; 9 | //uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | // FragColor = mix(texture(texture0, ourTexel), 16 | // texture(texture1, ourTexel), val_alpha); 17 | FragColor = mix(vec4(0.0f, 1.0f, 0.0f, 1.0f), 18 | vec4(0.0f, 0.0f, 1.0f, 1.0f), 19 | val_alpha); 20 | } 21 | -------------------------------------------------------------------------------- /057_3D_Sphere_Cube_Cone_AppleSoc/ShaderSource/cube.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | //layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | //out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | // ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /057_3D_Sphere_Cube_Cone_AppleSoc/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | //in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | //uniform sampler2D texture0; 8 | //uniform sampler2D texture1; 9 | //uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | // FragColor = mix(texture(texture0, ourTexel), 16 | // texture(texture1, ourTexel), val_alpha); 17 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 18 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 19 | val_alpha); 20 | } 21 | -------------------------------------------------------------------------------- /057_3D_Sphere_Cube_Cone_AppleSoc/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | //layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | //out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | // ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /057_3D_Sphere_Cube_Cone_AppleSoc/ShaderSource/sphere.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform float val_alpha; 5 | 6 | void main() 7 | { 8 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 9 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 10 | val_alpha); 11 | } 12 | -------------------------------------------------------------------------------- /057_3D_Sphere_Cube_Cone_AppleSoc/ShaderSource/sphere.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /057_3D_Sphere_Cube_Cone_AppleSoc/cube.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CUBE_H 2 | #define CUBE_H 3 | 4 | 5 | #include 6 | #include 7 | 8 | const float LENGTH = 1.0f; 9 | 10 | 11 | class Cube 12 | { 13 | public: 14 | Cube(); 15 | Cube(const float length); 16 | 17 | private: 18 | void _genVectorVerticesAndIndices(); 19 | 20 | public: 21 | std::vector vertices; // 顶点 22 | 23 | QMatrix4x4 mat_model; 24 | 25 | private: 26 | float _length; 27 | }; 28 | 29 | #endif // CUBE_H 30 | -------------------------------------------------------------------------------- /057_3D_Sphere_Cube_Cone_AppleSoc/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | 9 | QSurfaceFormat format; 10 | format.setMajorVersion(3); 11 | format.setMinorVersion(3); 12 | format.setProfile(QSurfaceFormat::CoreProfile); 13 | QSurfaceFormat::setDefaultFormat(format); 14 | 15 | 16 | MainWindow w; 17 | w.show(); 18 | 19 | return a.exec(); 20 | } 21 | -------------------------------------------------------------------------------- /057_3D_Sphere_Cube_Cone_AppleSoc/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/sphere.frag 4 | ShaderSource/sphere.vert 5 | ShaderSource/cube.frag 6 | ShaderSource/cube.vert 7 | ShaderSource/cone.frag 8 | ShaderSource/cone.vert 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /060_Lighting_init/ShaderSource/cone.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform float val_alpha; 5 | 6 | void main() 7 | { 8 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 9 | vec4(0.0f, 0.0f, 1.0f, 1.0f), 10 | val_alpha); 11 | } 12 | -------------------------------------------------------------------------------- /060_Lighting_init/ShaderSource/cone.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /060_Lighting_init/ShaderSource/cube.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform vec3 object_color; 5 | uniform vec3 light_color; 6 | 7 | //in vec2 ourTexel; 8 | 9 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 10 | //uniform sampler2D texture0; 11 | //uniform sampler2D texture1; 12 | //uniform sampler2D texture2; 13 | 14 | uniform float val_alpha; 15 | 16 | void main() 17 | { 18 | // FragColor = mix(texture(texture0, ourTexel), 19 | // texture(texture1, ourTexel), val_alpha); 20 | FragColor = vec4(light_color * object_color, 1.0); 21 | } 22 | -------------------------------------------------------------------------------- /060_Lighting_init/ShaderSource/cube.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | //layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | //out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | // ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /060_Lighting_init/ShaderSource/light.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform vec3 light_color; 5 | 6 | void main() 7 | { 8 | FragColor = vec4(light_color, 1.0); 9 | } 10 | -------------------------------------------------------------------------------- /060_Lighting_init/ShaderSource/light.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | 5 | uniform mat4 mat_model; 6 | uniform mat4 mat_view; 7 | uniform mat4 mat_projection; 8 | 9 | void main() 10 | { 11 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 12 | } 13 | -------------------------------------------------------------------------------- /060_Lighting_init/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | //in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | //uniform sampler2D texture0; 8 | //uniform sampler2D texture1; 9 | //uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | // FragColor = mix(texture(texture0, ourTexel), 16 | // texture(texture1, ourTexel), val_alpha); 17 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 18 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 19 | val_alpha); 20 | } 21 | -------------------------------------------------------------------------------- /060_Lighting_init/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | //layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | //out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | // ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /060_Lighting_init/ShaderSource/sphere.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform float val_alpha; 5 | 6 | void main() 7 | { 8 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 9 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 10 | val_alpha); 11 | } 12 | -------------------------------------------------------------------------------- /060_Lighting_init/ShaderSource/sphere.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /060_Lighting_init/cube.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CUBE_H 2 | #define CUBE_H 3 | 4 | 5 | #include 6 | #include 7 | 8 | const float LENGTH = 1.0f; 9 | 10 | 11 | class Cube 12 | { 13 | public: 14 | Cube(); 15 | Cube(const float length); 16 | 17 | private: 18 | void _genVectorVerticesAndIndices(); 19 | 20 | public: 21 | std::vector vertices; // 顶点 22 | 23 | QMatrix4x4 mat_model; 24 | 25 | private: 26 | float _length; 27 | }; 28 | 29 | #endif // CUBE_H 30 | -------------------------------------------------------------------------------- /060_Lighting_init/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /060_Lighting_init/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/sphere.frag 4 | ShaderSource/sphere.vert 5 | ShaderSource/cube.frag 6 | ShaderSource/cube.vert 7 | ShaderSource/cone.frag 8 | ShaderSource/cone.vert 9 | ShaderSource/light.frag 10 | ShaderSource/light.vert 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /060_Lighting_init_AppleSoc/ShaderSource/cone.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform float val_alpha; 5 | 6 | void main() 7 | { 8 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 9 | vec4(0.0f, 0.0f, 1.0f, 1.0f), 10 | val_alpha); 11 | } 12 | -------------------------------------------------------------------------------- /060_Lighting_init_AppleSoc/ShaderSource/cone.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /060_Lighting_init_AppleSoc/ShaderSource/cube.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform vec3 object_color; // 物体颜色 5 | uniform vec3 light_color; // 环境光颜色 6 | 7 | void main() 8 | { 9 | FragColor = vec4(object_color * light_color, 1.0f); 10 | } 11 | -------------------------------------------------------------------------------- /060_Lighting_init_AppleSoc/ShaderSource/cube.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /060_Lighting_init_AppleSoc/ShaderSource/light.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | 5 | uniform vec3 light_color; 6 | 7 | void main() 8 | { 9 | FragColor = vec4(light_color, 1.0f); 10 | } 11 | -------------------------------------------------------------------------------- /060_Lighting_init_AppleSoc/ShaderSource/light.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /060_Lighting_init_AppleSoc/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | //in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | //uniform sampler2D texture0; 8 | //uniform sampler2D texture1; 9 | //uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | // FragColor = mix(texture(texture0, ourTexel), 16 | // texture(texture1, ourTexel), val_alpha); 17 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 18 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 19 | val_alpha); 20 | } 21 | -------------------------------------------------------------------------------- /060_Lighting_init_AppleSoc/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | //layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | //out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | // ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /060_Lighting_init_AppleSoc/ShaderSource/sphere.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform float val_alpha; 5 | 6 | void main() 7 | { 8 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 9 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 10 | val_alpha); 11 | } 12 | -------------------------------------------------------------------------------- /060_Lighting_init_AppleSoc/ShaderSource/sphere.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /060_Lighting_init_AppleSoc/cube.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CUBE_H 2 | #define CUBE_H 3 | 4 | 5 | #include 6 | #include 7 | 8 | const float LENGTH = 1.0f; 9 | 10 | 11 | class Cube 12 | { 13 | public: 14 | Cube(); 15 | Cube(const float length); 16 | 17 | private: 18 | void _genVectorVerticesAndIndices(); 19 | 20 | public: 21 | std::vector vertices; // 顶点 22 | 23 | QMatrix4x4 mat_model; 24 | 25 | private: 26 | float _length; 27 | }; 28 | 29 | #endif // CUBE_H 30 | -------------------------------------------------------------------------------- /060_Lighting_init_AppleSoc/light.h: -------------------------------------------------------------------------------- 1 | #ifndef LIGHT_H 2 | #define LIGHT_H 3 | #include 4 | #include 5 | 6 | 7 | const float LENGTH_LIGHT = 1.0f; 8 | 9 | 10 | class Light 11 | { 12 | public: 13 | Light(); 14 | Light(const float length, QVector3D color); 15 | 16 | 17 | private: 18 | void _genVectorVerticesAndIndices(); 19 | 20 | 21 | public: 22 | QMatrix4x4 mat_model; 23 | QVector3D color; 24 | std::vector vertices; // 顶点 25 | 26 | 27 | private: 28 | float _length; 29 | }; 30 | 31 | #endif // LIGHT_H 32 | -------------------------------------------------------------------------------- /060_Lighting_init_AppleSoc/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | 9 | QSurfaceFormat format; 10 | format.setMajorVersion(3); 11 | format.setMinorVersion(3); 12 | format.setProfile(QSurfaceFormat::CoreProfile); 13 | QSurfaceFormat::setDefaultFormat(format); 14 | 15 | 16 | MainWindow w; 17 | w.show(); 18 | 19 | return a.exec(); 20 | } 21 | -------------------------------------------------------------------------------- /060_Lighting_init_AppleSoc/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/sphere.frag 4 | ShaderSource/sphere.vert 5 | ShaderSource/cube.frag 6 | ShaderSource/cube.vert 7 | ShaderSource/cone.frag 8 | ShaderSource/cone.vert 9 | ShaderSource/light.frag 10 | ShaderSource/light.vert 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /061_Light_Phong/ShaderSource/cone.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform float val_alpha; 5 | 6 | void main() 7 | { 8 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 9 | vec4(0.0f, 0.0f, 1.0f, 1.0f), 10 | val_alpha); 11 | } 12 | -------------------------------------------------------------------------------- /061_Light_Phong/ShaderSource/cone.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /061_Light_Phong/ShaderSource/cube.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | layout (location = 1) in vec3 aNormal; // 法线值 4 | 5 | out vec3 g_axis_normal; 6 | out vec3 g_axis_fragPos; 7 | 8 | uniform mat4 mat_model; 9 | uniform mat4 mat_view; 10 | uniform mat4 mat_projection; 11 | 12 | void main() 13 | { 14 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 15 | 16 | g_axis_normal = mat3(transpose(inverse(mat_model))) * aNormal; // 将模型[法线]的坐标转换到世界坐标 17 | g_axis_fragPos = vec3(mat_model * vec4(aPos, 1.0)); // 将模型[片段]的坐标转换到世界坐标 18 | } 19 | -------------------------------------------------------------------------------- /061_Light_Phong/ShaderSource/light.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform vec3 light_color; 5 | 6 | void main() 7 | { 8 | FragColor = vec4(light_color, 1.0f); 9 | } 10 | -------------------------------------------------------------------------------- /061_Light_Phong/ShaderSource/light.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /061_Light_Phong/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | //in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | //uniform sampler2D texture0; 8 | //uniform sampler2D texture1; 9 | //uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | // FragColor = mix(texture(texture0, ourTexel), 16 | // texture(texture1, ourTexel), val_alpha); 17 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 18 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 19 | val_alpha); 20 | } 21 | -------------------------------------------------------------------------------- /061_Light_Phong/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | //layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | //out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | // ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /061_Light_Phong/ShaderSource/sphere.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform float val_alpha; 5 | 6 | void main() 7 | { 8 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 9 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 10 | val_alpha); 11 | } 12 | -------------------------------------------------------------------------------- /061_Light_Phong/ShaderSource/sphere.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /061_Light_Phong/cube.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CUBE_H 2 | #define CUBE_H 3 | 4 | 5 | #include 6 | #include 7 | 8 | const float LENGTH = 1.0f; 9 | const QVector3D COLOR_CUBE = QVector3D(1.0f, 0.5f, 0.3f); 10 | 11 | class Cube 12 | { 13 | public: 14 | Cube(); 15 | Cube(const float length, QVector3D color = COLOR_CUBE); 16 | 17 | private: 18 | void _genVectorVerticesAndIndices(); 19 | 20 | public: 21 | std::vector vertices; // 顶点 22 | 23 | QMatrix4x4 mat_model; 24 | QVector3D color; 25 | 26 | private: 27 | float _length; 28 | }; 29 | 30 | #endif // CUBE_H 31 | -------------------------------------------------------------------------------- /061_Light_Phong/light.h: -------------------------------------------------------------------------------- 1 | #ifndef LIGHT_H 2 | #define LIGHT_H 3 | #include 4 | #include 5 | 6 | 7 | const float LENGTH_LIGHT = 1.0f; 8 | 9 | 10 | class Light 11 | { 12 | public: 13 | Light(); 14 | Light(const float length, QVector3D color, QVector3D postion); 15 | 16 | 17 | private: 18 | void _genVectorVerticesAndIndices(); 19 | 20 | 21 | public: 22 | QMatrix4x4 mat_model; 23 | QVector3D postion; 24 | QVector3D color; 25 | std::vector vertices; // 顶点 26 | 27 | 28 | private: 29 | float _length; 30 | }; 31 | 32 | #endif // LIGHT_H 33 | -------------------------------------------------------------------------------- /061_Light_Phong/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | 9 | QSurfaceFormat format; 10 | format.setMajorVersion(3); 11 | format.setMinorVersion(3); 12 | format.setProfile(QSurfaceFormat::CoreProfile); 13 | QSurfaceFormat::setDefaultFormat(format); 14 | 15 | 16 | MainWindow w; 17 | w.show(); 18 | 19 | return a.exec(); 20 | } 21 | -------------------------------------------------------------------------------- /061_Light_Phong/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/sphere.frag 4 | ShaderSource/sphere.vert 5 | ShaderSource/cube.frag 6 | ShaderSource/cube.vert 7 | ShaderSource/cone.frag 8 | ShaderSource/cone.vert 9 | ShaderSource/light.frag 10 | ShaderSource/light.vert 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /062_Light_Phong_move_light/ShaderSource/cone.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform float val_alpha; 5 | 6 | void main() 7 | { 8 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 9 | vec4(0.0f, 0.0f, 1.0f, 1.0f), 10 | val_alpha); 11 | } 12 | -------------------------------------------------------------------------------- /062_Light_Phong_move_light/ShaderSource/cone.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /062_Light_Phong_move_light/ShaderSource/cube.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | layout (location = 1) in vec3 aNormal; // 法线值 4 | 5 | out vec3 g_axis_normal; 6 | out vec3 g_axis_fragPos; 7 | 8 | uniform mat4 mat_model; 9 | uniform mat4 mat_view; 10 | uniform mat4 mat_projection; 11 | 12 | void main() 13 | { 14 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 15 | 16 | g_axis_normal = mat3(transpose(inverse(mat_model))) * aNormal; // 将模型[法线]的坐标转换到世界坐标 17 | g_axis_fragPos = vec3(mat_model * vec4(aPos, 1.0)); // 将模型[片段]的坐标转换到世界坐标 18 | } 19 | -------------------------------------------------------------------------------- /062_Light_Phong_move_light/ShaderSource/light.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform vec3 light_color; 5 | 6 | void main() 7 | { 8 | FragColor = vec4(light_color, 1.0f); 9 | } 10 | -------------------------------------------------------------------------------- /062_Light_Phong_move_light/ShaderSource/light.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /062_Light_Phong_move_light/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | //in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | //uniform sampler2D texture0; 8 | //uniform sampler2D texture1; 9 | //uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | // FragColor = mix(texture(texture0, ourTexel), 16 | // texture(texture1, ourTexel), val_alpha); 17 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 18 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 19 | val_alpha); 20 | } 21 | -------------------------------------------------------------------------------- /062_Light_Phong_move_light/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | //layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | //out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | // ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /062_Light_Phong_move_light/ShaderSource/sphere.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform float val_alpha; 5 | 6 | void main() 7 | { 8 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 9 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 10 | val_alpha); 11 | } 12 | -------------------------------------------------------------------------------- /062_Light_Phong_move_light/ShaderSource/sphere.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /062_Light_Phong_move_light/cube.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CUBE_H 2 | #define CUBE_H 3 | 4 | 5 | #include 6 | #include 7 | 8 | const float LENGTH = 1.0f; 9 | const QVector3D COLOR_CUBE = QVector3D(1.0f, 0.5f, 0.3f); 10 | 11 | class Cube 12 | { 13 | public: 14 | Cube(); 15 | Cube(const float length, QVector3D color = COLOR_CUBE); 16 | 17 | private: 18 | void _genVectorVerticesAndIndices(); 19 | 20 | public: 21 | std::vector vertices; // 顶点 22 | 23 | QMatrix4x4 mat_model; 24 | QVector3D color; 25 | 26 | private: 27 | float _length; 28 | }; 29 | 30 | #endif // CUBE_H 31 | -------------------------------------------------------------------------------- /062_Light_Phong_move_light/light.h: -------------------------------------------------------------------------------- 1 | #ifndef LIGHT_H 2 | #define LIGHT_H 3 | #include 4 | #include 5 | 6 | 7 | const float LENGTH_LIGHT = 1.0f; 8 | 9 | 10 | class Light 11 | { 12 | public: 13 | Light(); 14 | Light(const float length, QVector3D color, QVector3D postion); 15 | 16 | 17 | private: 18 | void _genVectorVerticesAndIndices(); 19 | 20 | 21 | public: 22 | QMatrix4x4 mat_model; 23 | QVector3D postion; 24 | QVector3D color; 25 | std::vector vertices; // 顶点 26 | 27 | 28 | private: 29 | float _length; 30 | }; 31 | 32 | #endif // LIGHT_H 33 | -------------------------------------------------------------------------------- /062_Light_Phong_move_light/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | 9 | QSurfaceFormat format; 10 | format.setMajorVersion(3); 11 | format.setMinorVersion(3); 12 | format.setProfile(QSurfaceFormat::CoreProfile); 13 | QSurfaceFormat::setDefaultFormat(format); 14 | 15 | 16 | MainWindow w; 17 | w.show(); 18 | 19 | return a.exec(); 20 | } 21 | -------------------------------------------------------------------------------- /062_Light_Phong_move_light/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/sphere.frag 4 | ShaderSource/sphere.vert 5 | ShaderSource/cube.frag 6 | ShaderSource/cube.vert 7 | ShaderSource/cone.frag 8 | ShaderSource/cone.vert 9 | ShaderSource/light.frag 10 | ShaderSource/light.vert 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /065_Light_Material/ShaderSource/cone.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform float val_alpha; 5 | 6 | void main() 7 | { 8 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 9 | vec4(0.0f, 0.0f, 1.0f, 1.0f), 10 | val_alpha); 11 | } 12 | -------------------------------------------------------------------------------- /065_Light_Material/ShaderSource/cone.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /065_Light_Material/ShaderSource/cube.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | layout (location = 1) in vec3 aNormal; // 法线值 4 | 5 | out vec3 g_axis_normal; 6 | out vec3 g_axis_fragPos; 7 | 8 | uniform mat4 mat_model; 9 | uniform mat4 mat_view; 10 | uniform mat4 mat_projection; 11 | 12 | void main() 13 | { 14 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 15 | 16 | g_axis_normal = mat3(transpose(inverse(mat_model))) * aNormal; // 将模型[法线]的坐标转换到世界坐标 17 | g_axis_fragPos = vec3(mat_model * vec4(aPos, 1.0)); // 将模型[片段]的坐标转换到世界坐标 18 | } 19 | -------------------------------------------------------------------------------- /065_Light_Material/ShaderSource/light.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform vec3 light_color; 5 | 6 | void main() 7 | { 8 | FragColor = vec4(light_color, 1.0f); 9 | } 10 | -------------------------------------------------------------------------------- /065_Light_Material/ShaderSource/light.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /065_Light_Material/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | //in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | //uniform sampler2D texture0; 8 | //uniform sampler2D texture1; 9 | //uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | // FragColor = mix(texture(texture0, ourTexel), 16 | // texture(texture1, ourTexel), val_alpha); 17 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 18 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 19 | val_alpha); 20 | } 21 | -------------------------------------------------------------------------------- /065_Light_Material/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | //layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | //out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | // ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /065_Light_Material/ShaderSource/sphere.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform float val_alpha; 5 | 6 | void main() 7 | { 8 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 9 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 10 | val_alpha); 11 | } 12 | -------------------------------------------------------------------------------- /065_Light_Material/ShaderSource/sphere.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /065_Light_Material/cube.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CUBE_H 2 | #define CUBE_H 3 | 4 | 5 | #include 6 | #include 7 | 8 | const float LENGTH = 1.0f; 9 | const QVector3D COLOR_CUBE = QVector3D(1.0f, 0.5f, 0.3f); 10 | 11 | class Cube 12 | { 13 | public: 14 | Cube(); 15 | Cube(const float length, QVector3D color = COLOR_CUBE); 16 | 17 | private: 18 | void _genVectorVerticesAndIndices(); 19 | 20 | public: 21 | std::vector vertices; // 顶点 22 | 23 | QMatrix4x4 mat_model; 24 | QVector3D color; 25 | 26 | private: 27 | float _length; 28 | }; 29 | 30 | #endif // CUBE_H 31 | -------------------------------------------------------------------------------- /065_Light_Material/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | 9 | QSurfaceFormat format; 10 | format.setMajorVersion(3); 11 | format.setMinorVersion(3); 12 | format.setProfile(QSurfaceFormat::CoreProfile); 13 | QSurfaceFormat::setDefaultFormat(format); 14 | 15 | 16 | MainWindow w; 17 | w.show(); 18 | 19 | return a.exec(); 20 | } 21 | -------------------------------------------------------------------------------- /065_Light_Material/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/sphere.frag 4 | ShaderSource/sphere.vert 5 | ShaderSource/cube.frag 6 | ShaderSource/cube.vert 7 | ShaderSource/cone.frag 8 | ShaderSource/cone.vert 9 | ShaderSource/light.frag 10 | ShaderSource/light.vert 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /066_Light_Texture_Map/Picture/wood_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/066_Light_Texture_Map/Picture/wood_box.png -------------------------------------------------------------------------------- /066_Light_Texture_Map/Picture/wood_box_specular_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/066_Light_Texture_Map/Picture/wood_box_specular_map.png -------------------------------------------------------------------------------- /066_Light_Texture_Map/ShaderSource/cone.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform float val_alpha; 5 | 6 | void main() 7 | { 8 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 9 | vec4(0.0f, 0.0f, 1.0f, 1.0f), 10 | val_alpha); 11 | } 12 | -------------------------------------------------------------------------------- /066_Light_Texture_Map/ShaderSource/cone.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /066_Light_Texture_Map/ShaderSource/light.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform vec3 light_color; 5 | 6 | void main() 7 | { 8 | FragColor = vec4(light_color, 1.0f); 9 | } 10 | -------------------------------------------------------------------------------- /066_Light_Texture_Map/ShaderSource/light.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /066_Light_Texture_Map/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | //in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | //uniform sampler2D texture0; 8 | //uniform sampler2D texture1; 9 | //uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | // FragColor = mix(texture(texture0, ourTexel), 16 | // texture(texture1, ourTexel), val_alpha); 17 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 18 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 19 | val_alpha); 20 | } 21 | -------------------------------------------------------------------------------- /066_Light_Texture_Map/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | //layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | //out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | // ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /066_Light_Texture_Map/ShaderSource/sphere.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform float val_alpha; 5 | 6 | void main() 7 | { 8 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 9 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 10 | val_alpha); 11 | } 12 | -------------------------------------------------------------------------------- /066_Light_Texture_Map/ShaderSource/sphere.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /066_Light_Texture_Map/cube.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CUBE_H 2 | #define CUBE_H 3 | 4 | 5 | #include 6 | #include 7 | 8 | const float LENGTH = 1.0f; 9 | const QVector3D COLOR_CUBE = QVector3D(1.0f, 0.5f, 0.3f); 10 | 11 | class Cube 12 | { 13 | public: 14 | Cube(); 15 | Cube(const float length, QVector3D color = COLOR_CUBE); 16 | 17 | private: 18 | void _genVectorVerticesAndIndices(); 19 | 20 | public: 21 | std::vector vertices; // 顶点 22 | 23 | QMatrix4x4 mat_model; 24 | QVector3D color; 25 | 26 | private: 27 | float _length; 28 | }; 29 | 30 | #endif // CUBE_H 31 | -------------------------------------------------------------------------------- /066_Light_Texture_Map/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | 9 | QSurfaceFormat format; 10 | format.setMajorVersion(3); 11 | format.setMinorVersion(3); 12 | format.setProfile(QSurfaceFormat::CoreProfile); 13 | QSurfaceFormat::setDefaultFormat(format); 14 | 15 | 16 | MainWindow w; 17 | w.show(); 18 | 19 | return a.exec(); 20 | } 21 | -------------------------------------------------------------------------------- /066_Light_Texture_Map/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/sphere.frag 4 | ShaderSource/sphere.vert 5 | ShaderSource/cube.frag 6 | ShaderSource/cube.vert 7 | ShaderSource/cone.frag 8 | ShaderSource/cone.vert 9 | ShaderSource/light.frag 10 | ShaderSource/light.vert 11 | 12 | 13 | Picture/wood_box.png 14 | Picture/wood_box_specular_map.png 15 | 16 | 17 | -------------------------------------------------------------------------------- /067_Light_Texture_Map_exercise/Picture/lighting_maps_specular_color.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/067_Light_Texture_Map_exercise/Picture/lighting_maps_specular_color.png -------------------------------------------------------------------------------- /067_Light_Texture_Map_exercise/Picture/matrix.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/067_Light_Texture_Map_exercise/Picture/matrix.jpg -------------------------------------------------------------------------------- /067_Light_Texture_Map_exercise/Picture/wood_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/067_Light_Texture_Map_exercise/Picture/wood_box.png -------------------------------------------------------------------------------- /067_Light_Texture_Map_exercise/Picture/wood_box_specular_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/067_Light_Texture_Map_exercise/Picture/wood_box_specular_map.png -------------------------------------------------------------------------------- /067_Light_Texture_Map_exercise/ShaderSource/cone.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform float val_alpha; 5 | 6 | void main() 7 | { 8 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 9 | vec4(0.0f, 0.0f, 1.0f, 1.0f), 10 | val_alpha); 11 | } 12 | -------------------------------------------------------------------------------- /067_Light_Texture_Map_exercise/ShaderSource/cone.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /067_Light_Texture_Map_exercise/ShaderSource/light.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform vec3 light_color; 5 | 6 | void main() 7 | { 8 | FragColor = vec4(light_color, 1.0f); 9 | } 10 | -------------------------------------------------------------------------------- /067_Light_Texture_Map_exercise/ShaderSource/light.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /067_Light_Texture_Map_exercise/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | //in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | //uniform sampler2D texture0; 8 | //uniform sampler2D texture1; 9 | //uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | // FragColor = mix(texture(texture0, ourTexel), 16 | // texture(texture1, ourTexel), val_alpha); 17 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 18 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 19 | val_alpha); 20 | } 21 | -------------------------------------------------------------------------------- /067_Light_Texture_Map_exercise/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | //layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | //out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | // ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /067_Light_Texture_Map_exercise/ShaderSource/sphere.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform float val_alpha; 5 | 6 | void main() 7 | { 8 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 9 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 10 | val_alpha); 11 | } 12 | -------------------------------------------------------------------------------- /067_Light_Texture_Map_exercise/ShaderSource/sphere.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /067_Light_Texture_Map_exercise/cube.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CUBE_H 2 | #define CUBE_H 3 | 4 | 5 | #include 6 | #include 7 | 8 | const float LENGTH = 1.0f; 9 | const QVector3D COLOR_CUBE = QVector3D(1.0f, 0.5f, 0.3f); 10 | 11 | class Cube 12 | { 13 | public: 14 | Cube(); 15 | Cube(const float length, QVector3D color = COLOR_CUBE); 16 | 17 | private: 18 | void _genVectorVerticesAndIndices(); 19 | 20 | public: 21 | std::vector vertices; // 顶点 22 | 23 | QMatrix4x4 mat_model; 24 | QVector3D color; 25 | 26 | private: 27 | float _length; 28 | }; 29 | 30 | #endif // CUBE_H 31 | -------------------------------------------------------------------------------- /068_Light_Texture_Map_All_Shape/Picture/light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/068_Light_Texture_Map_All_Shape/Picture/light.png -------------------------------------------------------------------------------- /068_Light_Texture_Map_All_Shape/Picture/poly_specular_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/068_Light_Texture_Map_All_Shape/Picture/poly_specular_map.png -------------------------------------------------------------------------------- /068_Light_Texture_Map_All_Shape/Picture/poly_tex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/068_Light_Texture_Map_All_Shape/Picture/poly_tex.png -------------------------------------------------------------------------------- /068_Light_Texture_Map_All_Shape/Picture/wood_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/068_Light_Texture_Map_All_Shape/Picture/wood_box.png -------------------------------------------------------------------------------- /068_Light_Texture_Map_All_Shape/Picture/wood_box_specular_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/068_Light_Texture_Map_All_Shape/Picture/wood_box_specular_map.png -------------------------------------------------------------------------------- /068_Light_Texture_Map_All_Shape/ShaderSource/light.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform vec3 light_color; 5 | 6 | void main() 7 | { 8 | FragColor = vec4(light_color, 1.0f); 9 | } 10 | -------------------------------------------------------------------------------- /068_Light_Texture_Map_All_Shape/ShaderSource/light.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /068_Light_Texture_Map_All_Shape/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | //in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | //uniform sampler2D texture0; 8 | //uniform sampler2D texture1; 9 | //uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | // FragColor = mix(texture(texture0, ourTexel), 16 | // texture(texture1, ourTexel), val_alpha); 17 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 18 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 19 | val_alpha); 20 | } 21 | -------------------------------------------------------------------------------- /068_Light_Texture_Map_All_Shape/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | //layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | //out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | // ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /068_Light_Texture_Map_All_Shape/cube.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CUBE_H 2 | #define CUBE_H 3 | 4 | 5 | #include 6 | #include 7 | 8 | const float LENGTH = 1.0f; 9 | const QVector3D COLOR_CUBE = QVector3D(1.0f, 0.5f, 0.3f); 10 | 11 | class Cube 12 | { 13 | public: 14 | Cube(); 15 | Cube(const float length, QVector3D color = COLOR_CUBE); 16 | 17 | private: 18 | void _genVectorVerticesAndIndices(); 19 | 20 | public: 21 | std::vector vertices; // 顶点 22 | 23 | QMatrix4x4 mat_model; 24 | QVector3D color; 25 | 26 | private: 27 | float _length; 28 | }; 29 | 30 | #endif // CUBE_H 31 | -------------------------------------------------------------------------------- /068_Light_Texture_Map_All_Shape/foxmath.h: -------------------------------------------------------------------------------- 1 | #ifndef FOXMATH_H 2 | #define FOXMATH_H 3 | 4 | # include 5 | 6 | /** 7 | * @brief 计算并返回由 3 各构成平面的法向量 8 | * @param p1 第一个点 9 | * @param p2 第二个点 10 | * @param p3 第三个点 11 | * @return 12 | */ 13 | inline QVector3D getNormalVector(QVector3D p1, QVector3D p2, QVector3D p3) 14 | { 15 | return QVector3D::crossProduct(p1, p2) 16 | + QVector3D::crossProduct(p2, p3) 17 | + QVector3D::crossProduct(p3, p1); 18 | } 19 | 20 | #endif // FOXMATH_H 21 | -------------------------------------------------------------------------------- /068_Light_Texture_Map_All_Shape/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #include "foxmath.h" 7 | 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | QApplication a(argc, argv); 12 | 13 | QSurfaceFormat format; 14 | format.setMajorVersion(3); 15 | format.setMinorVersion(3); 16 | format.setProfile(QSurfaceFormat::CoreProfile); 17 | QSurfaceFormat::setDefaultFormat(format); 18 | 19 | 20 | MainWindow w; 21 | w.show(); 22 | 23 | return a.exec(); 24 | } 25 | -------------------------------------------------------------------------------- /103_GLSL_FrontFacing/Picture/light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/103_GLSL_FrontFacing/Picture/light.png -------------------------------------------------------------------------------- /103_GLSL_FrontFacing/Picture/poly_specular_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/103_GLSL_FrontFacing/Picture/poly_specular_map.png -------------------------------------------------------------------------------- /103_GLSL_FrontFacing/Picture/poly_tex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/103_GLSL_FrontFacing/Picture/poly_tex.png -------------------------------------------------------------------------------- /103_GLSL_FrontFacing/Picture/wood_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/103_GLSL_FrontFacing/Picture/wood_box.png -------------------------------------------------------------------------------- /103_GLSL_FrontFacing/Picture/wood_box_specular_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/103_GLSL_FrontFacing/Picture/wood_box_specular_map.png -------------------------------------------------------------------------------- /103_GLSL_FrontFacing/ShaderSource/cone.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | layout (location = 1) in vec3 aNormal; // 法线值 4 | 5 | 6 | out vec3 g_axis_normal; 7 | out vec3 g_axis_fragPos; 8 | 9 | 10 | uniform mat4 mat_model; 11 | uniform mat4 mat_view; 12 | uniform mat4 mat_projection; 13 | 14 | void main() 15 | { 16 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 17 | 18 | g_axis_normal = mat3(transpose(inverse(mat_model))) * aNormal; // 将模型[法线]的坐标转换到世界坐标 19 | g_axis_fragPos = vec3(mat_model * vec4(aPos, 1.0)); // 将模型[片段]的坐标转换到世界坐标 20 | } 21 | -------------------------------------------------------------------------------- /103_GLSL_FrontFacing/ShaderSource/light.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform vec3 light_color; 5 | 6 | void main() 7 | { 8 | FragColor = vec4(light_color, 1.0f); 9 | } 10 | -------------------------------------------------------------------------------- /103_GLSL_FrontFacing/ShaderSource/light.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /103_GLSL_FrontFacing/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | //in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | //uniform sampler2D texture0; 8 | //uniform sampler2D texture1; 9 | //uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | // FragColor = mix(texture(texture0, ourTexel), 16 | // texture(texture1, ourTexel), val_alpha); 17 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 18 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 19 | val_alpha); 20 | } 21 | -------------------------------------------------------------------------------- /103_GLSL_FrontFacing/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | //layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | //out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | // ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /103_GLSL_FrontFacing/ShaderSource/sphere.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | layout (location = 1) in vec3 aNormal; // 法线值 4 | 5 | 6 | out vec3 g_axis_normal; 7 | out vec3 g_axis_fragPos; 8 | 9 | 10 | uniform mat4 mat_model; 11 | uniform mat4 mat_view; 12 | uniform mat4 mat_projection; 13 | 14 | void main() 15 | { 16 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 17 | 18 | g_axis_normal = mat3(transpose(inverse(mat_model))) * aNormal; // 将模型[法线]的坐标转换到世界坐标 19 | g_axis_fragPos = vec3(mat_model * vec4(aPos, 1.0)); // 将模型[片段]的坐标转换到世界坐标 20 | } 21 | -------------------------------------------------------------------------------- /103_GLSL_FrontFacing/cube.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CUBE_H 2 | #define CUBE_H 3 | 4 | 5 | #include 6 | #include 7 | 8 | const float LENGTH = 1.0f; 9 | const QVector3D COLOR_CUBE = QVector3D(1.0f, 0.5f, 0.3f); 10 | 11 | class Cube 12 | { 13 | public: 14 | Cube(); 15 | Cube(const float length, QVector3D color = COLOR_CUBE); 16 | 17 | private: 18 | void _genVectorVerticesAndIndices(); 19 | 20 | public: 21 | std::vector vertices; // 顶点 22 | 23 | QMatrix4x4 mat_model; 24 | QVector3D color; 25 | 26 | private: 27 | float _length; 28 | }; 29 | 30 | #endif // CUBE_H 31 | -------------------------------------------------------------------------------- /103_GLSL_FrontFacing/foxmath.h: -------------------------------------------------------------------------------- 1 | #ifndef FOXMATH_H 2 | #define FOXMATH_H 3 | 4 | # include 5 | 6 | /** 7 | * @brief 计算并返回由 3 各构成平面的法向量 8 | * @param p1 第一个点 9 | * @param p2 第二个点 10 | * @param p3 第三个点 11 | * @return 12 | */ 13 | inline QVector3D getNormalVector(QVector3D p1, QVector3D p2, QVector3D p3) 14 | { 15 | return QVector3D::crossProduct(p1, p2) 16 | + QVector3D::crossProduct(p2, p3) 17 | + QVector3D::crossProduct(p3, p1); 18 | } 19 | 20 | #endif // FOXMATH_H 21 | -------------------------------------------------------------------------------- /103_GLSL_FrontFacing/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #include "foxmath.h" 7 | 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | QApplication a(argc, argv); 12 | 13 | QSurfaceFormat format; 14 | format.setMajorVersion(3); 15 | format.setMinorVersion(3); 16 | format.setProfile(QSurfaceFormat::CoreProfile); 17 | QSurfaceFormat::setDefaultFormat(format); 18 | 19 | 20 | MainWindow w; 21 | w.show(); 22 | 23 | return a.exec(); 24 | } 25 | -------------------------------------------------------------------------------- /110_Geometry_Shader/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | void main() 5 | { 6 | FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f); 7 | } 8 | -------------------------------------------------------------------------------- /110_Geometry_Shader/ShaderSource/source.geom: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (points) in; 3 | layout (line_strip, max_vertices = 2) out; 4 | 5 | void main() { 6 | gl_Position = gl_in[0].gl_Position + vec4(-0.1, 0.0, 0.0, 0.0); EmitVertex(); 7 | gl_Position = gl_in[0].gl_Position + vec4( 0.1, 0.0, 0.0, 0.0); EmitVertex(); 8 | 9 | // gl_Pointsize = gl_in[0].gl_Pointsize; 10 | // EmitVertex(); 11 | 12 | EndPrimitive(); 13 | } 14 | -------------------------------------------------------------------------------- /110_Geometry_Shader/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; 3 | 4 | void main() 5 | { 6 | gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0f); 7 | gl_PointSize = 10; 8 | } 9 | -------------------------------------------------------------------------------- /110_Geometry_Shader/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | 9 | /** 10 | * 在 M1 的 Mac 要设置这里 11 | * !!3.3 的版本可用,但是 4.5 用不了!,initializeOpenGLFunctions 返回 false 12 | */ 13 | QSurfaceFormat format; 14 | format.setMajorVersion(3); 15 | format.setMinorVersion(3); 16 | format.setProfile(QSurfaceFormat::CoreProfile); 17 | QSurfaceFormat::setDefaultFormat(format); 18 | 19 | 20 | MainWindow w; 21 | w.show(); 22 | 23 | return a.exec(); 24 | } 25 | -------------------------------------------------------------------------------- /110_Geometry_Shader/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void on_actionDrawRect_triggered(); 20 | 21 | void on_actionWireframe_triggered(); 22 | 23 | void on_actionClear_triggered(); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | }; 28 | 29 | #endif // MAINWINDOW_H 30 | -------------------------------------------------------------------------------- /110_Geometry_Shader/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/source.frag 4 | ShaderSource/source.vert 5 | ShaderSource/source.geom 6 | 7 | 8 | -------------------------------------------------------------------------------- /111_Geometry_House/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | in vec3 fColor; 4 | 5 | out vec4 FragColor; 6 | 7 | void main() 8 | { 9 | FragColor = vec4(fColor, 1.0f); 10 | } 11 | -------------------------------------------------------------------------------- /111_Geometry_House/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec2 aPos; 3 | layout (location = 1) in vec3 aColor; 4 | 5 | out VS_OUT { 6 | vec3 color; 7 | } vs_out; 8 | 9 | void main() 10 | { 11 | gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0); 12 | vs_out.color = aColor; 13 | } 14 | -------------------------------------------------------------------------------- /111_Geometry_House/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | 9 | /** 10 | * 在 M1 的 Mac 要设置这里 11 | * !!3.3 的版本可用,但是 4.5 用不了!,initializeOpenGLFunctions 返回 false 12 | */ 13 | QSurfaceFormat format; 14 | format.setMajorVersion(3); 15 | format.setMinorVersion(3); 16 | format.setProfile(QSurfaceFormat::CoreProfile); 17 | QSurfaceFormat::setDefaultFormat(format); 18 | 19 | 20 | MainWindow w; 21 | w.show(); 22 | 23 | return a.exec(); 24 | } 25 | -------------------------------------------------------------------------------- /111_Geometry_House/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void on_actionDrawRect_triggered(); 20 | 21 | void on_actionWireframe_triggered(); 22 | 23 | void on_actionClear_triggered(); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | }; 28 | 29 | #endif // MAINWINDOW_H 30 | -------------------------------------------------------------------------------- /111_Geometry_House/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/source.frag 4 | ShaderSource/source.vert 5 | ShaderSource/source.geom 6 | 7 | 8 | -------------------------------------------------------------------------------- /112_Geometry_Bezier_2D/Picture/light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/112_Geometry_Bezier_2D/Picture/light.png -------------------------------------------------------------------------------- /112_Geometry_Bezier_2D/Picture/poly_specular_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/112_Geometry_Bezier_2D/Picture/poly_specular_map.png -------------------------------------------------------------------------------- /112_Geometry_Bezier_2D/Picture/poly_tex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/112_Geometry_Bezier_2D/Picture/poly_tex.png -------------------------------------------------------------------------------- /112_Geometry_Bezier_2D/Picture/wood_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/112_Geometry_Bezier_2D/Picture/wood_box.png -------------------------------------------------------------------------------- /112_Geometry_Bezier_2D/Picture/wood_box_specular_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/112_Geometry_Bezier_2D/Picture/wood_box_specular_map.png -------------------------------------------------------------------------------- /112_Geometry_Bezier_2D/ShaderSource/light.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform vec3 light_color; 5 | 6 | void main() 7 | { 8 | FragColor = vec4(light_color, 1.0f); 9 | } 10 | -------------------------------------------------------------------------------- /112_Geometry_Bezier_2D/ShaderSource/light.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /112_Geometry_Bezier_2D/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | //in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | //uniform sampler2D texture0; 8 | //uniform sampler2D texture1; 9 | //uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | // FragColor = mix(texture(texture0, ourTexel), 16 | // texture(texture1, ourTexel), val_alpha); 17 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 18 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 19 | val_alpha); 20 | } 21 | -------------------------------------------------------------------------------- /112_Geometry_Bezier_2D/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | //layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | //out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | // ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /112_Geometry_Bezier_2D/cube.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CUBE_H 2 | #define CUBE_H 3 | 4 | 5 | #include 6 | #include 7 | 8 | const float LENGTH = 1.0f; 9 | const QVector3D COLOR_CUBE = QVector3D(1.0f, 0.5f, 0.3f); 10 | 11 | class Cube 12 | { 13 | public: 14 | Cube(); 15 | Cube(const float length, QVector3D color = COLOR_CUBE); 16 | 17 | private: 18 | void _genVectorVerticesAndIndices(); 19 | 20 | public: 21 | std::vector vertices; // 顶点 22 | 23 | QMatrix4x4 mat_model; 24 | QVector3D color; 25 | 26 | private: 27 | float _length; 28 | }; 29 | 30 | #endif // CUBE_H 31 | -------------------------------------------------------------------------------- /112_Geometry_Bezier_2D/foxmath.h: -------------------------------------------------------------------------------- 1 | #ifndef FOXMATH_H 2 | #define FOXMATH_H 3 | 4 | # include 5 | 6 | /** 7 | * @brief 计算并返回由 3 各构成平面的法向量 8 | * @param p1 第一个点 9 | * @param p2 第二个点 10 | * @param p3 第三个点 11 | * @return 12 | */ 13 | inline QVector3D getNormalVector(QVector3D p1, QVector3D p2, QVector3D p3) 14 | { 15 | return QVector3D::crossProduct(p1, p2) 16 | + QVector3D::crossProduct(p2, p3) 17 | + QVector3D::crossProduct(p3, p1); 18 | } 19 | 20 | #endif // FOXMATH_H 21 | -------------------------------------------------------------------------------- /112_Geometry_Bezier_2D/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #include "foxmath.h" 7 | 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | QApplication a(argc, argv); 12 | 13 | QSurfaceFormat format; 14 | format.setMajorVersion(3); 15 | format.setMinorVersion(3); 16 | format.setProfile(QSurfaceFormat::CoreProfile); 17 | QSurfaceFormat::setDefaultFormat(format); 18 | 19 | 20 | MainWindow w; 21 | w.show(); 22 | 23 | return a.exec(); 24 | } 25 | -------------------------------------------------------------------------------- /112_Geometry_normal_ explode/Picture/light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/112_Geometry_normal_ explode/Picture/light.png -------------------------------------------------------------------------------- /112_Geometry_normal_ explode/Picture/poly_specular_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/112_Geometry_normal_ explode/Picture/poly_specular_map.png -------------------------------------------------------------------------------- /112_Geometry_normal_ explode/Picture/poly_tex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/112_Geometry_normal_ explode/Picture/poly_tex.png -------------------------------------------------------------------------------- /112_Geometry_normal_ explode/Picture/wood_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/112_Geometry_normal_ explode/Picture/wood_box.png -------------------------------------------------------------------------------- /112_Geometry_normal_ explode/Picture/wood_box_specular_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/112_Geometry_normal_ explode/Picture/wood_box_specular_map.png -------------------------------------------------------------------------------- /112_Geometry_normal_ explode/ShaderSource/light.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform vec3 light_color; 5 | 6 | void main() 7 | { 8 | FragColor = vec4(light_color, 1.0f); 9 | } 10 | -------------------------------------------------------------------------------- /112_Geometry_normal_ explode/ShaderSource/light.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /112_Geometry_normal_ explode/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | //in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | //uniform sampler2D texture0; 8 | //uniform sampler2D texture1; 9 | //uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | // FragColor = mix(texture(texture0, ourTexel), 16 | // texture(texture1, ourTexel), val_alpha); 17 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 18 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 19 | val_alpha); 20 | } 21 | -------------------------------------------------------------------------------- /112_Geometry_normal_ explode/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | //layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | //out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | // ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /112_Geometry_normal_ explode/cube.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CUBE_H 2 | #define CUBE_H 3 | 4 | 5 | #include 6 | #include 7 | 8 | const float LENGTH = 1.0f; 9 | const QVector3D COLOR_CUBE = QVector3D(1.0f, 0.5f, 0.3f); 10 | 11 | class Cube 12 | { 13 | public: 14 | Cube(); 15 | Cube(const float length, QVector3D color = COLOR_CUBE); 16 | 17 | private: 18 | void _genVectorVerticesAndIndices(); 19 | 20 | public: 21 | std::vector vertices; // 顶点 22 | 23 | QMatrix4x4 mat_model; 24 | QVector3D color; 25 | 26 | private: 27 | float _length; 28 | }; 29 | 30 | #endif // CUBE_H 31 | -------------------------------------------------------------------------------- /112_Geometry_normal_ explode/foxmath.h: -------------------------------------------------------------------------------- 1 | #ifndef FOXMATH_H 2 | #define FOXMATH_H 3 | 4 | # include 5 | 6 | /** 7 | * @brief 计算并返回由 3 各构成平面的法向量 8 | * @param p1 第一个点 9 | * @param p2 第二个点 10 | * @param p3 第三个点 11 | * @return 12 | */ 13 | inline QVector3D getNormalVector(QVector3D p1, QVector3D p2, QVector3D p3) 14 | { 15 | return QVector3D::crossProduct(p1, p2) 16 | + QVector3D::crossProduct(p2, p3) 17 | + QVector3D::crossProduct(p3, p1); 18 | } 19 | 20 | #endif // FOXMATH_H 21 | -------------------------------------------------------------------------------- /112_Geometry_normal_ explode/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #include "foxmath.h" 7 | 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | QApplication a(argc, argv); 12 | 13 | QSurfaceFormat format; 14 | format.setMajorVersion(3); 15 | format.setMinorVersion(3); 16 | format.setProfile(QSurfaceFormat::CoreProfile); 17 | QSurfaceFormat::setDefaultFormat(format); 18 | 19 | 20 | MainWindow w; 21 | w.show(); 22 | 23 | return a.exec(); 24 | } 25 | -------------------------------------------------------------------------------- /115_Geometry_Sphere_change/Picture/ball.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/115_Geometry_Sphere_change/Picture/ball.png -------------------------------------------------------------------------------- /115_Geometry_Sphere_change/Picture/light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/115_Geometry_Sphere_change/Picture/light.png -------------------------------------------------------------------------------- /115_Geometry_Sphere_change/ShaderSource/light.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform vec3 light_color; 5 | 6 | void main() 7 | { 8 | FragColor = vec4(light_color, 1.0f); 9 | } 10 | -------------------------------------------------------------------------------- /115_Geometry_Sphere_change/ShaderSource/light.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /115_Geometry_Sphere_change/foxmath.h: -------------------------------------------------------------------------------- 1 | #ifndef FOXMATH_H 2 | #define FOXMATH_H 3 | 4 | # include 5 | 6 | /** 7 | * @brief 计算并返回由 3 各构成平面的法向量 8 | * @param p1 第一个点 9 | * @param p2 第二个点 10 | * @param p3 第三个点 11 | * @return 12 | */ 13 | inline QVector3D getNormalVector(QVector3D p1, QVector3D p2, QVector3D p3) 14 | { 15 | return QVector3D::crossProduct(p1, p2) 16 | + QVector3D::crossProduct(p2, p3) 17 | + QVector3D::crossProduct(p3, p1); 18 | } 19 | 20 | #endif // FOXMATH_H 21 | -------------------------------------------------------------------------------- /115_Geometry_Sphere_change/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #include "foxmath.h" 7 | 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | QApplication a(argc, argv); 12 | 13 | QSurfaceFormat format; 14 | format.setMajorVersion(3); 15 | format.setMinorVersion(3); 16 | format.setProfile(QSurfaceFormat::CoreProfile); 17 | QSurfaceFormat::setDefaultFormat(format); 18 | 19 | 20 | MainWindow w; 21 | w.show(); 22 | 23 | return a.exec(); 24 | } 25 | -------------------------------------------------------------------------------- /115_Geometry_Sphere_change/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void on_actionWireframe_triggered(); 20 | 21 | void on_actionDrawSphere_triggered(); 22 | 23 | void on_actionMoveSphare_triggered(); 24 | 25 | void on_actionLightColor_triggered(); 26 | 27 | private: 28 | Ui::MainWindow *ui; 29 | }; 30 | 31 | #endif // MAINWINDOW_H 32 | -------------------------------------------------------------------------------- /115_Geometry_Sphere_change/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/sphere.frag 4 | ShaderSource/sphere.vert 5 | ShaderSource/light.frag 6 | ShaderSource/light.vert 7 | ShaderSource/sphere.geom 8 | 9 | 10 | Picture/light.png 11 | Picture/ball.png 12 | 13 | 14 | -------------------------------------------------------------------------------- /116_Geometry_Cone_change/Picture/light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/116_Geometry_Cone_change/Picture/light.png -------------------------------------------------------------------------------- /116_Geometry_Cone_change/ShaderSource/cone.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | void main() 5 | { 6 | gl_Position = vec4(aPos, 1.0); 7 | } 8 | -------------------------------------------------------------------------------- /116_Geometry_Cone_change/ShaderSource/light.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform vec3 light_color; 5 | 6 | void main() 7 | { 8 | FragColor = vec4(light_color, 1.0f); 9 | } 10 | -------------------------------------------------------------------------------- /116_Geometry_Cone_change/ShaderSource/light.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /116_Geometry_Cone_change/ShaderSource/sphere.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | layout (location = 1) in vec3 aNormal; // 法线值 4 | 5 | 6 | out vec3 g_axis_normal; 7 | out vec3 g_axis_fragPos; 8 | 9 | 10 | uniform mat4 mat_model; 11 | uniform mat4 mat_view; 12 | uniform mat4 mat_projection; 13 | 14 | void main() 15 | { 16 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 17 | 18 | g_axis_normal = mat3(transpose(inverse(mat_model))) * aNormal; // 将模型[法线]的坐标转换到世界坐标 19 | g_axis_fragPos = vec3(mat_model * vec4(aPos, 1.0)); // 将模型[片段]的坐标转换到世界坐标 20 | } 21 | -------------------------------------------------------------------------------- /116_Geometry_Cone_change/foxmath.h: -------------------------------------------------------------------------------- 1 | #ifndef FOXMATH_H 2 | #define FOXMATH_H 3 | 4 | # include 5 | 6 | /** 7 | * @brief 计算并返回由 3 各构成平面的法向量 8 | * @param p1 第一个点 9 | * @param p2 第二个点 10 | * @param p3 第三个点 11 | * @return 12 | */ 13 | inline QVector3D getNormalVector(QVector3D p1, QVector3D p2, QVector3D p3) 14 | { 15 | return QVector3D::crossProduct(p1, p2) 16 | + QVector3D::crossProduct(p2, p3) 17 | + QVector3D::crossProduct(p3, p1); 18 | } 19 | 20 | #endif // FOXMATH_H 21 | -------------------------------------------------------------------------------- /116_Geometry_Cone_change/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #include "foxmath.h" 7 | 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | QApplication a(argc, argv); 12 | 13 | QSurfaceFormat format; 14 | format.setMajorVersion(3); 15 | format.setMinorVersion(3); 16 | format.setProfile(QSurfaceFormat::CoreProfile); 17 | QSurfaceFormat::setDefaultFormat(format); 18 | 19 | 20 | MainWindow w; 21 | w.show(); 22 | 23 | return a.exec(); 24 | } 25 | -------------------------------------------------------------------------------- /116_Geometry_Cone_change/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/sphere.frag 4 | ShaderSource/sphere.vert 5 | ShaderSource/cone.frag 6 | ShaderSource/cone.vert 7 | ShaderSource/light.frag 8 | ShaderSource/light.vert 9 | ShaderSource/cone.geom 10 | 11 | 12 | Picture/light.png 13 | 14 | 15 | -------------------------------------------------------------------------------- /117_Geometry_Cone2Rocket/Picture/light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/117_Geometry_Cone2Rocket/Picture/light.png -------------------------------------------------------------------------------- /117_Geometry_Cone2Rocket/ShaderSource/cone.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | void main() 5 | { 6 | gl_Position = vec4(aPos, 1.0); 7 | } 8 | -------------------------------------------------------------------------------- /117_Geometry_Cone2Rocket/ShaderSource/light.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform vec3 light_color; 5 | 6 | void main() 7 | { 8 | FragColor = vec4(light_color, 1.0f); 9 | } 10 | -------------------------------------------------------------------------------- /117_Geometry_Cone2Rocket/ShaderSource/light.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /117_Geometry_Cone2Rocket/ShaderSource/sphere.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | layout (location = 1) in vec3 aNormal; // 法线值 4 | 5 | 6 | out vec3 g_axis_normal; 7 | out vec3 g_axis_fragPos; 8 | 9 | 10 | uniform mat4 mat_model; 11 | uniform mat4 mat_view; 12 | uniform mat4 mat_projection; 13 | 14 | void main() 15 | { 16 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 17 | 18 | g_axis_normal = mat3(transpose(inverse(mat_model))) * aNormal; // 将模型[法线]的坐标转换到世界坐标 19 | g_axis_fragPos = vec3(mat_model * vec4(aPos, 1.0)); // 将模型[片段]的坐标转换到世界坐标 20 | } 21 | -------------------------------------------------------------------------------- /117_Geometry_Cone2Rocket/foxmath.h: -------------------------------------------------------------------------------- 1 | #ifndef FOXMATH_H 2 | #define FOXMATH_H 3 | 4 | # include 5 | 6 | /** 7 | * @brief 计算并返回由 3 各构成平面的法向量 8 | * @param p1 第一个点 9 | * @param p2 第二个点 10 | * @param p3 第三个点 11 | * @return 12 | */ 13 | inline QVector3D getNormalVector(QVector3D p1, QVector3D p2, QVector3D p3) 14 | { 15 | return QVector3D::crossProduct(p1, p2) 16 | + QVector3D::crossProduct(p2, p3) 17 | + QVector3D::crossProduct(p3, p1); 18 | } 19 | 20 | #endif // FOXMATH_H 21 | -------------------------------------------------------------------------------- /117_Geometry_Cone2Rocket/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #include "foxmath.h" 7 | 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | QApplication a(argc, argv); 12 | 13 | QSurfaceFormat format; 14 | format.setMajorVersion(3); 15 | format.setMinorVersion(3); 16 | format.setProfile(QSurfaceFormat::CoreProfile); 17 | QSurfaceFormat::setDefaultFormat(format); 18 | 19 | 20 | MainWindow w; 21 | w.show(); 22 | 23 | return a.exec(); 24 | } 25 | -------------------------------------------------------------------------------- /117_Geometry_Cone2Rocket/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/sphere.frag 4 | ShaderSource/sphere.vert 5 | ShaderSource/cone.frag 6 | ShaderSource/cone.vert 7 | ShaderSource/light.frag 8 | ShaderSource/light.vert 9 | ShaderSource/cone.geom 10 | 11 | 12 | Picture/light.png 13 | 14 | 15 | -------------------------------------------------------------------------------- /117_Geometry_Cone2Rocket_Winonws/Picture/light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/117_Geometry_Cone2Rocket_Winonws/Picture/light.png -------------------------------------------------------------------------------- /117_Geometry_Cone2Rocket_Winonws/ShaderSource/cone.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | void main() 5 | { 6 | gl_Position = vec4(aPos, 1.0); 7 | } 8 | -------------------------------------------------------------------------------- /117_Geometry_Cone2Rocket_Winonws/ShaderSource/light.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform vec3 light_color; 5 | 6 | void main() 7 | { 8 | FragColor = vec4(light_color, 1.0f); 9 | } 10 | -------------------------------------------------------------------------------- /117_Geometry_Cone2Rocket_Winonws/ShaderSource/light.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /117_Geometry_Cone2Rocket_Winonws/foxmath.h: -------------------------------------------------------------------------------- 1 | #ifndef FOXMATH_H 2 | #define FOXMATH_H 3 | 4 | # include 5 | 6 | /** 7 | * @brief 计算并返回由 3 各构成平面的法向量 8 | * @param p1 第一个点 9 | * @param p2 第二个点 10 | * @param p3 第三个点 11 | * @return 12 | */ 13 | inline QVector3D getNormalVector(QVector3D p1, QVector3D p2, QVector3D p3) 14 | { 15 | return QVector3D::crossProduct(p1, p2) 16 | + QVector3D::crossProduct(p2, p3) 17 | + QVector3D::crossProduct(p3, p1); 18 | } 19 | 20 | #endif // FOXMATH_H 21 | -------------------------------------------------------------------------------- /117_Geometry_Cone2Rocket_Winonws/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #include "foxmath.h" 7 | 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | QApplication a(argc, argv); 12 | 13 | QSurfaceFormat format; 14 | format.setMajorVersion(3); 15 | format.setMinorVersion(3); 16 | format.setProfile(QSurfaceFormat::CoreProfile); 17 | QSurfaceFormat::setDefaultFormat(format); 18 | 19 | 20 | MainWindow w; 21 | w.show(); 22 | 23 | return a.exec(); 24 | } 25 | -------------------------------------------------------------------------------- /117_Geometry_Cone2Rocket_Winonws/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/sphere.frag 4 | ShaderSource/sphere.vert 5 | ShaderSource/cone.frag 6 | ShaderSource/cone.vert 7 | ShaderSource/light.frag 8 | ShaderSource/light.vert 9 | ShaderSource/cone.geom 10 | 11 | 12 | Picture/light.png 13 | 14 | 15 | -------------------------------------------------------------------------------- /120_Bezier_2D/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | void main() 5 | { 6 | FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f); 7 | } 8 | -------------------------------------------------------------------------------- /120_Bezier_2D/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; 3 | 4 | 5 | out VS_OUT{ 6 | int id; 7 | } vs_out; 8 | 9 | 10 | void main() 11 | { 12 | gl_Position = vec4(aPos.x + 0.2f, aPos.y + 0.2f, aPos.z, 1.0f); 13 | 14 | vs_out.id = gl_VertexID; 15 | } 16 | -------------------------------------------------------------------------------- /120_Bezier_2D/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | 9 | /** 10 | * 在 M1 的 Mac 要设置这里 11 | * !!3.3 的版本可用,但是 4.5 用不了!,initializeOpenGLFunctions 返回 false 12 | */ 13 | QSurfaceFormat format; 14 | format.setMajorVersion(3); 15 | format.setMinorVersion(3); 16 | format.setProfile(QSurfaceFormat::CoreProfile); 17 | QSurfaceFormat::setDefaultFormat(format); 18 | 19 | 20 | MainWindow w; 21 | w.show(); 22 | 23 | return a.exec(); 24 | } 25 | -------------------------------------------------------------------------------- /120_Bezier_2D/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void on_actionDrawRect_triggered(); 20 | 21 | void on_actionWireframe_triggered(); 22 | 23 | void on_actionClear_triggered(); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | }; 28 | 29 | #endif // MAINWINDOW_H 30 | -------------------------------------------------------------------------------- /120_Bezier_2D/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ShaderSource/source.frag 4 | ShaderSource/source.vert 5 | ShaderSource/source.geom 6 | 7 | 8 | -------------------------------------------------------------------------------- /130_Physical_putdown_model/Picture/light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/130_Physical_putdown_model/Picture/light.png -------------------------------------------------------------------------------- /130_Physical_putdown_model/Picture/poly_specular_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/130_Physical_putdown_model/Picture/poly_specular_map.png -------------------------------------------------------------------------------- /130_Physical_putdown_model/Picture/poly_tex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/130_Physical_putdown_model/Picture/poly_tex.png -------------------------------------------------------------------------------- /130_Physical_putdown_model/Picture/wood_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/130_Physical_putdown_model/Picture/wood_box.png -------------------------------------------------------------------------------- /130_Physical_putdown_model/Picture/wood_box_specular_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/130_Physical_putdown_model/Picture/wood_box_specular_map.png -------------------------------------------------------------------------------- /130_Physical_putdown_model/ShaderSource/light.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform vec3 light_color; 5 | 6 | void main() 7 | { 8 | FragColor = vec4(light_color, 1.0f); 9 | } 10 | -------------------------------------------------------------------------------- /130_Physical_putdown_model/ShaderSource/light.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /130_Physical_putdown_model/ShaderSource/octahedron.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | void main() 5 | { 6 | gl_Position = vec4(aPos, 1.0); 7 | } 8 | -------------------------------------------------------------------------------- /130_Physical_putdown_model/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | //in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | //uniform sampler2D texture0; 8 | //uniform sampler2D texture1; 9 | //uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | // FragColor = mix(texture(texture0, ourTexel), 16 | // texture(texture1, ourTexel), val_alpha); 17 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 18 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 19 | val_alpha); 20 | } 21 | -------------------------------------------------------------------------------- /130_Physical_putdown_model/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | //layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | //out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | // ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /130_Physical_putdown_model/cube.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CUBE_H 2 | #define CUBE_H 3 | 4 | 5 | #include 6 | #include 7 | 8 | const float LENGTH = 1.0f; 9 | const QVector3D COLOR_CUBE = QVector3D(1.0f, 0.5f, 0.3f); 10 | 11 | class Cube 12 | { 13 | public: 14 | Cube(); 15 | Cube(const float length, QVector3D color = COLOR_CUBE); 16 | 17 | private: 18 | void _genVectorVerticesAndIndices(); 19 | 20 | public: 21 | std::vector vertices; // 顶点 22 | 23 | QMatrix4x4 mat_model; 24 | QVector3D color; 25 | 26 | private: 27 | float _length; 28 | }; 29 | 30 | #endif // CUBE_H 31 | -------------------------------------------------------------------------------- /130_Physical_putdown_model/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #include "foxmath.h" 7 | 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | QApplication a(argc, argv); 12 | 13 | QSurfaceFormat format; 14 | format.setMajorVersion(3); 15 | format.setMinorVersion(3); 16 | format.setProfile(QSurfaceFormat::CoreProfile); 17 | QSurfaceFormat::setDefaultFormat(format); 18 | 19 | 20 | MainWindow w; 21 | w.show(); 22 | 23 | return a.exec(); 24 | } 25 | -------------------------------------------------------------------------------- /130_Physical_putdown_model/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | 20 | void on_actionDrawCube_triggered(); 21 | 22 | void on_actionMoveCube_triggered(); 23 | 24 | void on_actionWireframe_triggered(); 25 | 26 | void on_actionLightColor_triggered(); 27 | 28 | private: 29 | Ui::MainWindow *ui; 30 | }; 31 | 32 | #endif // MAINWINDOW_H 33 | -------------------------------------------------------------------------------- /135_Physical_roll_model_old_method/Picture/light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/135_Physical_roll_model_old_method/Picture/light.png -------------------------------------------------------------------------------- /135_Physical_roll_model_old_method/Picture/poly_specular_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/135_Physical_roll_model_old_method/Picture/poly_specular_map.png -------------------------------------------------------------------------------- /135_Physical_roll_model_old_method/Picture/poly_tex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/135_Physical_roll_model_old_method/Picture/poly_tex.png -------------------------------------------------------------------------------- /135_Physical_roll_model_old_method/Picture/wood_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/135_Physical_roll_model_old_method/Picture/wood_box.png -------------------------------------------------------------------------------- /135_Physical_roll_model_old_method/Picture/wood_box_specular_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/135_Physical_roll_model_old_method/Picture/wood_box_specular_map.png -------------------------------------------------------------------------------- /135_Physical_roll_model_old_method/ShaderSource/light.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform vec3 light_color; 5 | 6 | void main() 7 | { 8 | FragColor = vec4(light_color, 1.0f); 9 | } 10 | -------------------------------------------------------------------------------- /135_Physical_roll_model_old_method/ShaderSource/light.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /135_Physical_roll_model_old_method/ShaderSource/octahedron.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | void main() 5 | { 6 | gl_Position = vec4(aPos, 1.0); 7 | } 8 | -------------------------------------------------------------------------------- /135_Physical_roll_model_old_method/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | //in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | //uniform sampler2D texture0; 8 | //uniform sampler2D texture1; 9 | //uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | // FragColor = mix(texture(texture0, ourTexel), 16 | // texture(texture1, ourTexel), val_alpha); 17 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 18 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 19 | val_alpha); 20 | } 21 | -------------------------------------------------------------------------------- /135_Physical_roll_model_old_method/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | //layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | //out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | // ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /135_Physical_roll_model_old_method/cube.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CUBE_H 2 | #define CUBE_H 3 | 4 | 5 | #include 6 | #include 7 | 8 | const float LENGTH = 1.0f; 9 | const QVector3D COLOR_CUBE = QVector3D(1.0f, 0.5f, 0.3f); 10 | 11 | class Cube 12 | { 13 | public: 14 | Cube(); 15 | Cube(const float length, QVector3D color = COLOR_CUBE); 16 | 17 | private: 18 | void _genVectorVerticesAndIndices(); 19 | 20 | public: 21 | std::vector vertices; // 顶点 22 | 23 | QMatrix4x4 mat_model; 24 | QVector3D color; 25 | 26 | private: 27 | float _length; 28 | }; 29 | 30 | #endif // CUBE_H 31 | -------------------------------------------------------------------------------- /135_Physical_roll_model_old_method/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #include "foxmath.h" 7 | 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | QApplication a(argc, argv); 12 | 13 | QSurfaceFormat format; 14 | format.setMajorVersion(3); 15 | format.setMinorVersion(3); 16 | format.setProfile(QSurfaceFormat::CoreProfile); 17 | QSurfaceFormat::setDefaultFormat(format); 18 | 19 | 20 | MainWindow w; 21 | w.show(); 22 | 23 | return a.exec(); 24 | } 25 | -------------------------------------------------------------------------------- /136_Physical_roll_model/Picture/light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/136_Physical_roll_model/Picture/light.png -------------------------------------------------------------------------------- /136_Physical_roll_model/Picture/poly_specular_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/136_Physical_roll_model/Picture/poly_specular_map.png -------------------------------------------------------------------------------- /136_Physical_roll_model/Picture/poly_tex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/136_Physical_roll_model/Picture/poly_tex.png -------------------------------------------------------------------------------- /136_Physical_roll_model/Picture/start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/136_Physical_roll_model/Picture/start.png -------------------------------------------------------------------------------- /136_Physical_roll_model/Picture/wood_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/136_Physical_roll_model/Picture/wood_box.png -------------------------------------------------------------------------------- /136_Physical_roll_model/Picture/wood_box_specular_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/136_Physical_roll_model/Picture/wood_box_specular_map.png -------------------------------------------------------------------------------- /136_Physical_roll_model/ShaderSource/light.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform vec3 light_color; 5 | 6 | void main() 7 | { 8 | FragColor = vec4(light_color, 1.0f); 9 | } 10 | -------------------------------------------------------------------------------- /136_Physical_roll_model/ShaderSource/light.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /136_Physical_roll_model/ShaderSource/octahedron.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | void main() 5 | { 6 | gl_Position = vec4(aPos, 1.0); 7 | } 8 | -------------------------------------------------------------------------------- /136_Physical_roll_model/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | //in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | //uniform sampler2D texture0; 8 | //uniform sampler2D texture1; 9 | //uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | // FragColor = mix(texture(texture0, ourTexel), 16 | // texture(texture1, ourTexel), val_alpha); 17 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 18 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 19 | val_alpha); 20 | } 21 | -------------------------------------------------------------------------------- /136_Physical_roll_model/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | //layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | //out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | // ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /136_Physical_roll_model/cube.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CUBE_H 2 | #define CUBE_H 3 | 4 | 5 | #include 6 | #include 7 | 8 | const float LENGTH = 1.0f; 9 | const QVector3D COLOR_CUBE = QVector3D(1.0f, 0.5f, 0.3f); 10 | 11 | class Cube 12 | { 13 | public: 14 | Cube(); 15 | Cube(const float length, QVector3D color = COLOR_CUBE); 16 | 17 | private: 18 | void _genVectorVerticesAndIndices(); 19 | 20 | public: 21 | std::vector vertices; // 顶点 22 | 23 | QMatrix4x4 mat_model; 24 | QVector3D color; 25 | 26 | private: 27 | float _length; 28 | }; 29 | 30 | #endif // CUBE_H 31 | -------------------------------------------------------------------------------- /136_Physical_roll_model/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #include "foxmath.hpp" 7 | 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | QApplication a(argc, argv); 12 | 13 | QSurfaceFormat format; 14 | format.setMajorVersion(3); 15 | format.setMinorVersion(3); 16 | format.setProfile(QSurfaceFormat::CoreProfile); 17 | QSurfaceFormat::setDefaultFormat(format); 18 | 19 | 20 | MainWindow w; 21 | w.show(); 22 | 23 | return a.exec(); 24 | } 25 | -------------------------------------------------------------------------------- /137_Physical_roll_model_with_SPEED/Picture/light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/137_Physical_roll_model_with_SPEED/Picture/light.png -------------------------------------------------------------------------------- /137_Physical_roll_model_with_SPEED/Picture/poly_specular_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/137_Physical_roll_model_with_SPEED/Picture/poly_specular_map.png -------------------------------------------------------------------------------- /137_Physical_roll_model_with_SPEED/Picture/poly_tex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/137_Physical_roll_model_with_SPEED/Picture/poly_tex.png -------------------------------------------------------------------------------- /137_Physical_roll_model_with_SPEED/Picture/start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/137_Physical_roll_model_with_SPEED/Picture/start.png -------------------------------------------------------------------------------- /137_Physical_roll_model_with_SPEED/Picture/wood_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/137_Physical_roll_model_with_SPEED/Picture/wood_box.png -------------------------------------------------------------------------------- /137_Physical_roll_model_with_SPEED/Picture/wood_box_specular_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/137_Physical_roll_model_with_SPEED/Picture/wood_box_specular_map.png -------------------------------------------------------------------------------- /137_Physical_roll_model_with_SPEED/ShaderSource/light.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform vec3 light_color; 5 | 6 | void main() 7 | { 8 | FragColor = vec4(light_color, 1.0f); 9 | } 10 | -------------------------------------------------------------------------------- /137_Physical_roll_model_with_SPEED/ShaderSource/light.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; 3 | 4 | uniform mat4 mat_model; 5 | uniform mat4 mat_view; 6 | uniform mat4 mat_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 11 | } 12 | -------------------------------------------------------------------------------- /137_Physical_roll_model_with_SPEED/ShaderSource/octahedron.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | 4 | void main() 5 | { 6 | gl_Position = vec4(aPos, 1.0); 7 | } 8 | -------------------------------------------------------------------------------- /137_Physical_roll_model_with_SPEED/ShaderSource/source.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | //in vec2 ourTexel; 5 | 6 | // (纹理单元)其实自己不用写,默认是有的,用于传入纹理数据;【sampler是采样器】 7 | //uniform sampler2D texture0; 8 | //uniform sampler2D texture1; 9 | //uniform sampler2D texture2; 10 | 11 | uniform float val_alpha; 12 | 13 | void main() 14 | { 15 | // FragColor = mix(texture(texture0, ourTexel), 16 | // texture(texture1, ourTexel), val_alpha); 17 | FragColor = mix(vec4(1.0f, 0.0f, 0.0f, 1.0f), 18 | vec4(0.0f, 1.0f, 0.0f, 1.0f), 19 | val_alpha); 20 | } 21 | -------------------------------------------------------------------------------- /137_Physical_roll_model_with_SPEED/ShaderSource/source.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; // 位置变量的属性位置值为 0 3 | //layout (location = 1) in vec2 aTexel; // 存储2D纹理坐标s、t 4 | 5 | //out vec2 ourTexel; // 向片段着色器输出2D纹理坐标s、t 6 | 7 | uniform mat4 mat_model; 8 | uniform mat4 mat_view; 9 | uniform mat4 mat_projection; 10 | 11 | void main() 12 | { 13 | gl_Position = mat_projection * mat_view * mat_model * vec4(aPos, 1.0); // 乘以矩阵实现旋转和位移的效果,注意矩阵运算方向 14 | 15 | // ourTexel = vec2(aTexel.s, aTexel.t); 16 | } 17 | -------------------------------------------------------------------------------- /137_Physical_roll_model_with_SPEED/cube.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CUBE_H 2 | #define CUBE_H 3 | 4 | 5 | #include 6 | #include 7 | 8 | const float LENGTH = 1.0f; 9 | const QVector3D COLOR_CUBE = QVector3D(1.0f, 0.5f, 0.3f); 10 | 11 | class Cube 12 | { 13 | public: 14 | Cube(); 15 | Cube(const float length, QVector3D color = COLOR_CUBE); 16 | 17 | private: 18 | void _genVectorVerticesAndIndices(); 19 | 20 | public: 21 | std::vector vertices; // 顶点 22 | 23 | QMatrix4x4 mat_model; 24 | QVector3D color; 25 | 26 | private: 27 | float _length; 28 | }; 29 | 30 | #endif // CUBE_H 31 | -------------------------------------------------------------------------------- /137_Physical_roll_model_with_SPEED/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #include "foxmath.hpp" 7 | 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | QApplication a(argc, argv); 12 | 13 | QSurfaceFormat format; 14 | format.setMajorVersion(3); 15 | format.setMinorVersion(3); 16 | format.setProfile(QSurfaceFormat::CoreProfile); 17 | QSurfaceFormat::setDefaultFormat(format); 18 | 19 | 20 | MainWindow w; 21 | w.show(); 22 | 23 | return a.exec(); 24 | } 25 | -------------------------------------------------------------------------------- /doc/pic/README/get-7417632.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/get-7417632.gif -------------------------------------------------------------------------------- /doc/pic/README/get.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/get.gif -------------------------------------------------------------------------------- /doc/pic/README/image-20220729182054940.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/image-20220729182054940.png -------------------------------------------------------------------------------- /doc/pic/README/image-20220808195106987.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/image-20220808195106987.png -------------------------------------------------------------------------------- /doc/pic/README/image-20220808195151096.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/image-20220808195151096.png -------------------------------------------------------------------------------- /doc/pic/README/image-20220812134100244.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/image-20220812134100244.png -------------------------------------------------------------------------------- /doc/pic/README/image-20220812155627459.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/image-20220812155627459.png -------------------------------------------------------------------------------- /doc/pic/README/image-20220905184211935.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/image-20220905184211935.png -------------------------------------------------------------------------------- /doc/pic/README/image-20220905184318358.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/image-20220905184318358.png -------------------------------------------------------------------------------- /doc/pic/README/image-20220905184413706.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/image-20220905184413706.png -------------------------------------------------------------------------------- /doc/pic/README/image-20220905184728533.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/image-20220905184728533.png -------------------------------------------------------------------------------- /doc/pic/README/image-20220905184859891.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/image-20220905184859891.png -------------------------------------------------------------------------------- /doc/pic/README/image-20220905200249305.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/image-20220905200249305.png -------------------------------------------------------------------------------- /doc/pic/README/image-20220912113006689.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/image-20220912113006689.png -------------------------------------------------------------------------------- /doc/pic/README/image-20220924215747209.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/image-20220924215747209.png -------------------------------------------------------------------------------- /doc/pic/README/image-20220924223451296.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/image-20220924223451296.png -------------------------------------------------------------------------------- /doc/pic/README/image-20220925164252267.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/image-20220925164252267.png -------------------------------------------------------------------------------- /doc/pic/README/image-20220926130550452.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/image-20220926130550452.png -------------------------------------------------------------------------------- /doc/pic/README/image-20220926130652221.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/image-20220926130652221.png -------------------------------------------------------------------------------- /doc/pic/README/image-20221002231151376.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/image-20221002231151376.png -------------------------------------------------------------------------------- /doc/pic/README/image-20221016125629225.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/image-20221016125629225.png -------------------------------------------------------------------------------- /doc/pic/README/image-20221017130117822.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/image-20221017130117822.png -------------------------------------------------------------------------------- /doc/pic/README/image-20221017144440108.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/image-20221017144440108.png -------------------------------------------------------------------------------- /doc/pic/README/image-20221017155258815.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/image-20221017155258815.png -------------------------------------------------------------------------------- /doc/pic/README/image-20221017161540264.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/image-20221017161540264.png -------------------------------------------------------------------------------- /doc/pic/README/image-20221019001455414.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/image-20221019001455414.png -------------------------------------------------------------------------------- /doc/pic/README/image-20221019005611230.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/image-20221019005611230.png -------------------------------------------------------------------------------- /doc/pic/README/image-20221101162841805.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/image-20221101162841805.png -------------------------------------------------------------------------------- /doc/pic/README/wood_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/wood_box.png -------------------------------------------------------------------------------- /doc/pic/README/wood_box_specular_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/README/wood_box_specular_map.png -------------------------------------------------------------------------------- /doc/pic/立方体旋转掉落.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekosilverfox/OpenGL/c4146efc0cb463d7a7c813760d68b5b48a95535b/doc/pic/立方体旋转掉落.gif --------------------------------------------------------------------------------