zoukankan      html  css  js  c++  java
  • Make a simple opengl app

    受不了main的各种callback,先设计第一版Application:

    #define GLEW_STATIC
    // GLEW
    #include <GL/glew.h>
    #include <chrono>
    #undef GLFW_DLL
    // GLFW
    #include <GLFW/glfw3.h>
    #include "AM_Utils.h"
    #include "AM_ErrorCheck.h"
    #include "AM_GeoPtrs.h"
    #include "AM_NamespaceDef.h"
    #include "AM_GameCamera.h"
    #include "AM_LoadShader.h"
    #include "AM_AppInterface.h"
    
    
    using namespace std;
    USE_ALGEBRAMSTER_NAMESPACE
    
    const int width = 800;
    const int height = 800;
    
    class App:public AM_AppInterface{
    public:
        App(int w, int h, const char*title):AM_AppInterface(w,h,title)
        {
        }
        void init() override{
            cout << ">>initialize geometry
    ";
    
            // Triangle
            float vertices[] = {
                    // positions          // colors
                    -0.5f,  -0.5f, 0.0f,   1.0f, 0.0f, 0.0f,
                    0.5f, -0.5f, 0.0f,   0.0f, 1.0f, 0.0f,
                    0.0f, 0.5f, 0.0f,   0.0f, 0.0f, 1.0f,
    
            };
            geoPtr->setupVertexBufferData(vertices, sizeof(vertices));
            geoPtr->addAttrib<float>(3, 6, 0);  // P     at  location 0
            geoPtr->addAttrib<float>(3, 6, 3);  // Cd    at  location 1
            geoPtr->unBind();
            
            glPatchParameteri(GL_PATCH_VERTICES,3);
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
            
            cout << ">>initialize shaders
    ";
            shaderPtr->loadVertexShader("shaders/tessellation/CP_01/vert.glsl");
            shaderPtr->loadFragmentShader("shaders/tessellation/CP_01/frag.glsl");
            shaderPtr->loadTessellationControlShader("shaders/tessellation/CP_01/tcs.glsl");
            shaderPtr->loadTessellationEvaluationShader("shaders/tessellation/CP_01/tes.glsl");
            shaderPtr->link();
            shaderPtr->use();
    
        }
        void onKey(int key) override{
            camPtr->onKey(key, this->floatMs);
        }
    
        void render() override{
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            glClearColor(0,0,0,1);
            glm::mat4 proj = AM_GameCamera::getProjMatrix(width, height, 45, 0.1, 10000.0f);
            glm::mat4 view = camPtr->getViewMatrix();
            // Render content
            shaderPtr->use();
            shaderPtr->setMat4("view", view);
            shaderPtr->setMat4("proj", proj);
            geoPtr->bind();
            GL_CALL(glDrawArrays(GL_PATCHES,0,3));
        }
    
    private:
        GL_GeoPtr geoPtr = MakeGeo();
        LoadShaderPtr shaderPtr = MakeShader();
        gameCameraPtr camPtr = MakeCamera();
    
    };
    
    int main(){
        auto app = std::make_shared<App> (width,height,"HelloGL");
        app->renderLoop();
        return 0;
    }

    瞬间清爽。下面将参考更多的文章修改app的表面。

  • 相关阅读:
    js正则还原和转义特殊字符
    element表格鼠标悬浮上带有点击事件的变红-:row-class-name
    elemen-table表格数据转换-formatter属性
    SVN的安装及汉化的
    element中关于input框
    VUE之兄弟组件 $emit和$on、$bus的用法
    关于element表单校验(二)
    关于element表单校验(一)
    element表格里数据处理
    各类手册收藏整理
  • 原文地址:https://www.cnblogs.com/gearslogy/p/13212645.html
Copyright © 2011-2022 走看看