feat: mesh from geo
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "gui/viewport/GLMesh.h"
|
||||
#include <GL/gl.h>
|
||||
#include <iostream>
|
||||
|
||||
GLMesh::GLMesh()
|
||||
@@ -21,23 +22,34 @@ void GLMesh::init()
|
||||
void GLMesh::initBuffers()
|
||||
{
|
||||
|
||||
float vertices[] = {
|
||||
vertexPosData = {
|
||||
-0.5f, -0.5f, 0.0f,
|
||||
0.5f, -0.5f, 0.0f,
|
||||
0.0f, 0.5f, 0.0f
|
||||
0.0f, 0.5f, 0.0f,
|
||||
0.5f, 0.5f, 0.0f
|
||||
};
|
||||
|
||||
indexData =
|
||||
{
|
||||
0, 1, 2, 1, 2, 3
|
||||
};
|
||||
|
||||
// create buffer of vertices
|
||||
glGenBuffers(1, &vbo);
|
||||
glGenBuffers(1, &vertexBuffer);
|
||||
// set purpose
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
|
||||
// store data in the buffer
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, vertexPosData.size()*sizeof(GLfloat), vertexPosData.data(), GL_STATIC_DRAW);
|
||||
|
||||
// gives the shader a way to read
|
||||
// gives the shader a way to read buffer data
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(GLfloat), (void*)0);
|
||||
// disable vertex attrib array
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glGenBuffers(1, &indexBuffer);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexData.size()*sizeof(GLint), indexData.data(), GL_STATIC_DRAW);
|
||||
|
||||
}
|
||||
|
||||
void GLMesh::bind()
|
||||
@@ -53,5 +65,9 @@ void GLMesh::unbind()
|
||||
void GLMesh::draw()
|
||||
{
|
||||
bind();
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
|
||||
// wireframe
|
||||
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
|
||||
|
||||
glDrawElements(GL_TRIANGLES, indexData.size(), GL_UNSIGNED_INT, 0);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include <GL/gl.h>
|
||||
#include <QOpenGLFunctions_3_2_Core>
|
||||
|
||||
class GLMesh
|
||||
@@ -7,7 +8,11 @@ class GLMesh
|
||||
public:
|
||||
GLMesh();
|
||||
GLuint vao;
|
||||
GLuint vbo;
|
||||
GLuint vertexBuffer;
|
||||
GLuint indexBuffer;
|
||||
|
||||
std::vector<GLfloat> vertexPosData;
|
||||
std::vector<GLint> indexData;
|
||||
|
||||
void init();
|
||||
void initBuffers();
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
#include "gui/viewport/ViewportGLWidget.h"
|
||||
#include "gui/viewport/GLMesh.h"
|
||||
#include "gui/viewport/ViewportGLWidget.h" #include "gui/viewport/GLMesh.h"
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include <glm/ext/matrix_clip_space.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <memory>
|
||||
#include <qtimer.h>
|
||||
#include "Engine/Operator/Geometry.h"
|
||||
|
||||
void ViewportGLWidget::initializeGL()
|
||||
{
|
||||
using namespace enzo;
|
||||
initializeOpenGLFunctions();
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
@@ -16,13 +17,13 @@ void ViewportGLWidget::initializeGL()
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_MULTISAMPLE);
|
||||
|
||||
triangleMesh_ = std::make_unique<GLMesh>();
|
||||
auto geo = std::make_unique<enzo::geo::Geometry>();
|
||||
triangleMesh_ = meshFromGeo(geo);
|
||||
gridMesh_ = std::make_unique<GLGrid>();
|
||||
|
||||
QSurfaceFormat fmt = context()->format();
|
||||
std::cout << "format: " << (fmt.renderableType() == QSurfaceFormat::OpenGLES ? "GLES" : "Desktop") << "\n";
|
||||
std::cout << "format: " << (fmt.renderableType() == QSurfaceFormat::OpenGL ? "true" : "false") << "\n";
|
||||
std::cout << "hello\n";
|
||||
|
||||
// init loop
|
||||
QTimer* loopTimer = new QTimer(this);
|
||||
@@ -136,3 +137,10 @@ void ViewportGLWidget::paintGL()
|
||||
|
||||
|
||||
}
|
||||
|
||||
std::unique_ptr<GLMesh> ViewportGLWidget::meshFromGeo(std::unique_ptr<enzo::geo::Geometry>& geometry)
|
||||
{
|
||||
auto mesh = std::make_unique<GLMesh>();
|
||||
return mesh;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "gui/viewport/GLCamera.h"
|
||||
#include "gui/viewport/GLMesh.h"
|
||||
#include "gui/viewport/GLGrid.h"
|
||||
#include "Engine/Operator/Geometry.h"
|
||||
|
||||
class ViewportGLWidget : public QOpenGLWidget, protected QOpenGLFunctions_3_2_Core
|
||||
{
|
||||
@@ -17,6 +18,8 @@ public:
|
||||
std::unique_ptr<GLMesh> triangleMesh_ ;
|
||||
std::unique_ptr<GLGrid> gridMesh_ ;
|
||||
|
||||
std::unique_ptr<GLMesh> meshFromGeo(std::unique_ptr<enzo::geo::Geometry>& geometry);
|
||||
|
||||
protected:
|
||||
void initializeGL() override;
|
||||
void resizeGL(int w, int h) override;
|
||||
|
||||
Reference in New Issue
Block a user