当前位置: 首页>>代码示例>>C++>>正文


C++ ProgramObject::set1ui方法代码示例

本文整理汇总了C++中ProgramObject::set1ui方法的典型用法代码示例。如果您正苦于以下问题:C++ ProgramObject::set1ui方法的具体用法?C++ ProgramObject::set1ui怎么用?C++ ProgramObject::set1ui使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ProgramObject的用法示例。


在下文中一共展示了ProgramObject::set1ui方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main


//.........这里部分代码省略.........
  GLuint vbo;

  bool wireframe = false;
  int starCount = 20000;
  int seed = 0;

  app.addInitCallback([&]() {
    string prefix = app.getResourceDir() + "shaders/Nei/n01_Planet/";
    auto vert = compileShader(GL_VERTEX_SHADER, Loader::text(prefix + "empty.vert"));
    auto tesc = compileShader(GL_TESS_CONTROL_SHADER, Loader::text(prefix + "planet.tesc"));
    auto tese = compileShader(GL_TESS_EVALUATION_SHADER, Loader::text(prefix + "planet.tese"));
    auto frag = compileShader(GL_FRAGMENT_SHADER, Loader::text(prefix + "planet.frag"));
    programPlanet = createProgram(vert, tesc, tese, frag);
    
    vert = compileShader(GL_VERTEX_SHADER, Loader::text(prefix + "empty.vert"));
    tesc = compileShader(GL_TESS_CONTROL_SHADER, Loader::text(prefix + "atmosphere.tesc"));
    tese = compileShader(GL_TESS_EVALUATION_SHADER, Loader::text(prefix + "atmosphere.tese"));
    frag = compileShader(GL_FRAGMENT_SHADER, Loader::text(prefix + "atmosphere.frag"));
    programAtmosphere = createProgram(vert, tesc, tese, frag);
    
    vert = compileShader(GL_VERTEX_SHADER, Loader::text(prefix + "stars.vert"));
    frag = compileShader(GL_FRAGMENT_SHADER, Loader::text(prefix + "stars.frag"));
    programStars = createProgram(vert, frag);

    glCreateVertexArrays(1, &vao);
    float distance = 400;

    vector<vec4> vec;
    vec.reserve(starCount);
    for (int i = 0; i<starCount; i++) {
      float a = ((float)rand() / RAND_MAX - 0.5);
      float b = ((float)rand() / RAND_MAX - 0.5);
      float c = ((float)rand() / RAND_MAX - 0.5);
      float d = (float)rand() / RAND_MAX * 5 + 1;

      vec4 v(a, b, c, 0);
      v = normalize(v);
      v *= distance;
      v.w = d;

      vec.push_back(v);
    }

    glCreateBuffers(1, &vbo);
    glNamedBufferData(vbo, sizeof(vec4)*vec.size(), vec.data(), GL_STATIC_DRAW);

    glVertexArrayVertexBuffer(vao, 0, vbo, 0, sizeof(vec4));
    glVertexArrayAttribFormat(vao, 0, 4, GL_FLOAT, 0, 0);
    glEnableVertexArrayAttrib(vao, 0);
    glBindVertexArray(vao);
  });
  app.addUpdateCallback([&](float dt) {
    manipulator.update(dt);
  });
  app.addDrawCallback([&]() {
    int w = mainWindow->getWidth();
    int h = mainWindow->getHeight();
    glViewport(0, 0, w, h);

    glClearColor(0, 0, 0, 1);
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);

    glPolygonMode(GL_FRONT_AND_BACK, wireframe ? GL_LINE : GL_FILL);

    programStars.use();
    programStars.setMatrix4fv("v", value_ptr(cam.getView()));
    programStars.setMatrix4fv("p", value_ptr(cam.getProjection()));

    glEnable(GL_PROGRAM_POINT_SIZE);    
    glDrawArrays(GL_POINTS, 0, starCount);

    
    programPlanet.use();
    programPlanet.setMatrix4fv("v", value_ptr(cam.getView()));
    programPlanet.setMatrix4fv("p", value_ptr(cam.getProjection()));
    programPlanet.set3fv("camPos", value_ptr(cam.getEye()));
    programPlanet.set1i("seed", seed);
    programPlanet.set1f("time", app.getTimeFromStart());

    glPatchParameteri(GL_PATCH_VERTICES, 1);
    glDrawArraysInstanced(GL_PATCHES, 0, 1, 16);
    
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    programAtmosphere.use();
    programAtmosphere.setMatrix4fv("v", value_ptr(cam.getView()));
    programAtmosphere.setMatrix4fv("p", value_ptr(cam.getProjection()));
    programAtmosphere.set3fv("camPos", value_ptr(cam.getEye()));
    programAtmosphere.set1ui("seed", seed);
    programAtmosphere.set1f("time", app.getTimeFromStart());

    glPatchParameteri(GL_PATCH_VERTICES, 1);
    glDrawArrays(GL_PATCHES, 0, 1);
  });
  return app.run();
}
开发者ID:dormon,项目名称:FitGL,代码行数:101,代码来源:main.cpp


注:本文中的ProgramObject::set1ui方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。