Browse Source

创建vbo,并给vbo传数据

master
blobt 4 years ago
parent
commit
9924c5b573
  1. BIN
      .vs/shader2/v14/.suo
  2. 19753
      glew.h
  3. 42
      main.cpp
  4. BIN
      shader2.VC.db

BIN
.vs/shader2/v14/.suo

19753
glew.h
File diff suppressed because it is too large
View File

42
main.cpp

@ -1,3 +1,4 @@
#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include "glew.h"
#include <gl/GL.h>
@ -5,6 +6,11 @@
#pragma comment(lib,"opengl32.lib")
#pragma comment(lib, "glew32.lib")
struct Vertex {
float pos[3];
float color[4];
};
/**
* @hwnd
* @msg
@ -38,6 +44,9 @@ char* LoadFileContent(const char *path) {
return fileContent;
}
/**
* GPU程序
*/
GLuint CreateGPUProgram(const char* vsShaderPath, const char* fsShaderPath) {
//创建program
GLuint program = glCreateProgram();
@ -136,8 +145,41 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
/*glew初始化*/
glewInit();
/*创建program*/
GLuint program = CreateGPUProgram("test.vs", "test.fs");
/*创建vbo*/
Vertex vertex[3];
vertex[0].pos[0] = 0;
vertex[0].pos[1] = 0;
vertex[0].pos[2] = -100.0f;
vertex[0].color[0] = 1.0f;
vertex[0].color[1] = 1.0f;
vertex[0].color[2] = 1.0f;
vertex[0].color[3] = 1.0f;
vertex[1].pos[0] = 10;
vertex[1].pos[1] = 0;
vertex[1].pos[2] = -100.0f;
vertex[1].color[0] = 1.0f;
vertex[1].color[1] = 1.0f;
vertex[1].color[2] = 1.0f;
vertex[1].color[3] = 1.0f;
vertex[2].pos[0] = 0;
vertex[2].pos[1] = 10;
vertex[2].pos[2] = -100.0f;
vertex[2].color[0] = 1.0f;
vertex[2].color[1] = 1.0f;
vertex[2].color[2] = 1.0f;
vertex[2].color[3] = 1.0f;
GLuint vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*7*3, vertex, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glClearColor(1.0f, 1.0f, 0.0f, 1.0f);
/*显示窗口*/

BIN
shader2.VC.db

Loading…
Cancel
Save