OpenGL:同时创建并渲染多个数据

  • 使用数组储存多个顶点数据
  • 同时渲染多个对象
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
using namespace std;
const unsigned int screen_width = 800;
const unsigned int screen_height = 600;

const char *vertexShaderSource = "#version 330 core\n"
                        "layout (location = 0) in vec3 aPos;\n"
                        "void main()\n"
                        "{\n"
                        "gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
                        "}\0";
const char *fragmentShaderSource = "#version 330 core\n"
                            "out vec4 FragColor;\n"
                            "void main()\n"
                            "{\n"
                            "FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
                            "}\0";

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

int main()
{
   
    //initialization and setting
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

    //Creating window and checking whether it is created or not;
    GLFWwindow * window = glfwCreateWindow(screen_width, screen_height, "MyWindow", nullptr, nullptr);
    if(window == nullptr)
    {
   
        cout << "Fail to create window." << endl;
        glfwTerminate();
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值