cube mesh
This commit is contained in:
parent
75b5e3bf3c
commit
73f4502dd3
3 changed files with 58 additions and 12 deletions
47
src/defaultmeshes.cpp
Normal file
47
src/defaultmeshes.cpp
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
#include "defaultmeshes.h"
|
||||||
|
|
||||||
|
Mesh* CUBE_MESH;
|
||||||
|
|
||||||
|
void initMeshes() {
|
||||||
|
static float vertices[] = {
|
||||||
|
// positions // normals // texture coords
|
||||||
|
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
||||||
|
0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
|
||||||
|
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
|
||||||
|
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
|
||||||
|
-0.5f, 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f,
|
||||||
|
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
||||||
|
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
||||||
|
0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
|
||||||
|
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
|
||||||
|
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
|
||||||
|
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f,
|
||||||
|
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
||||||
|
-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
|
||||||
|
-0.5f, 0.5f, -0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f,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
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
|
||||||
|
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
|
||||||
|
-0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
|
||||||
|
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
|
||||||
|
};
|
||||||
|
|
||||||
|
CUBE_MESH = new Mesh(36, vertices);
|
||||||
|
}
|
6
src/defaultmeshes.h
Normal file
6
src/defaultmeshes.h
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#pragma once
|
||||||
|
#include "mesh.h"
|
||||||
|
|
||||||
|
extern Mesh* CUBE_MESH;
|
||||||
|
|
||||||
|
void initMeshes();
|
|
@ -3,26 +3,19 @@
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include "shader.h"
|
#include "shader.h"
|
||||||
#include "mesh.h"
|
#include "mesh.h"
|
||||||
|
#include "defaultmeshes.h"
|
||||||
|
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
|
|
||||||
float verts[] {
|
|
||||||
// position // normals // tex coords
|
|
||||||
0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
|
||||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
|
||||||
1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
|
||||||
};
|
|
||||||
|
|
||||||
Shader *shader = NULL;
|
Shader *shader = NULL;
|
||||||
Mesh *triangleMesh = NULL;
|
|
||||||
|
|
||||||
void renderInit(GLFWwindow* window) {
|
void renderInit(GLFWwindow* window) {
|
||||||
glViewport(0, 0, 500, 500);
|
glViewport(0, 0, 500, 500);
|
||||||
|
|
||||||
|
initMeshes();
|
||||||
|
|
||||||
// Compile shader
|
// Compile shader
|
||||||
shader = new Shader("assets/shaders/orange.vs", "assets/shaders/orange.fs");
|
shader = new Shader("assets/shaders/orange.vs", "assets/shaders/orange.fs");
|
||||||
|
|
||||||
triangleMesh = new Mesh(3, verts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void render(GLFWwindow* window) {
|
void render(GLFWwindow* window) {
|
||||||
|
@ -32,6 +25,6 @@ void render(GLFWwindow* window) {
|
||||||
// Use shader
|
// Use shader
|
||||||
shader->use();
|
shader->use();
|
||||||
|
|
||||||
triangleMesh->bind();
|
CUBE_MESH->bind();
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue