summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjjesswan <jessica_wan@brown.edu>2024-05-09 23:53:08 -0400
committerjjesswan <jessica_wan@brown.edu>2024-05-09 23:53:08 -0400
commit4150f19230962abaf68a8be209c7fa10bc7691e3 (patch)
tree02b5c38f1b54c4e436010972e85cb44ef7641f4d /src
parentf9819ae7f8b11b298c16eb14d929a9c09038a877 (diff)
relative filepaths thanks joelll
Diffstat (limited to 'src')
-rw-r--r--src/arap.cpp10
-rwxr-xr-xsrc/glwidget.cpp135
-rwxr-xr-xsrc/glwidget.h1
-rw-r--r--src/ocean/ocean_alt.cpp2
-rw-r--r--src/ocean/ocean_alt.h8
-rw-r--r--src/skybox.cpp48
6 files changed, 66 insertions, 138 deletions
diff --git a/src/arap.cpp b/src/arap.cpp
index b6f2f8c..670f06e 100644
--- a/src/arap.cpp
+++ b/src/arap.cpp
@@ -51,8 +51,8 @@ void ARAP::init
coeffMin = all_vertices.colwise().minCoeff();
coeffMax = all_vertices.colwise().maxCoeff();
-// minCorner = coeffMin;
-// maxCorner = coeffMax;
+ minCorner = coeffMin;
+ maxCorner = coeffMax;
//
std::cout << "minCorner: " << minCorner << std::endl;
std::cout << "maxCorner: " << maxCorner << std::endl;
@@ -84,8 +84,8 @@ void ARAP::update(double seconds)
// the last update
m_ocean.fft_prime(m_time);
m_ocean.update_ocean();
-// m_shape.setVertices_and_Normals(m_ocean.get_vertices(), m_ocean.getNormals());
- m_shape.setVertices(m_ocean.get_vertices());
+ m_shape.setVertices_and_Normals(m_ocean.get_vertices(), m_ocean.getNormals());
+ // m_shape.setVertices(m_ocean.get_vertices());
// auto tmp = m_ocean.get_vertices();
// print the min and max of the vertices
@@ -99,7 +99,7 @@ void ARAP::update(double seconds)
//std::cout << "max: " << max << std::endl;
FoamConstants foam = m_ocean.getFoamConstants();
- m_foam_shape.setFoamInputs(m_shape.getVertices(), foam.wavelengths, foam.k_vectors, foam.texCoords);
+ m_foam_shape.setFoamInputs(m_ocean.m_vertices, foam.wavelengths, foam.k_vectors, foam.texCoords);
m_time += m_timestep;
diff --git a/src/glwidget.cpp b/src/glwidget.cpp
index 47df4f5..57b4468 100755
--- a/src/glwidget.cpp
+++ b/src/glwidget.cpp
@@ -98,13 +98,6 @@ void GLWidget::initializeGL()
m_foamShader = new Shader(":resources/shaders/foam.vert", ":resources/shaders/foam.frag");
m_skyboxShader = new Shader(":resources/shaders/skybox.vert", ":resources/shaders/skybox.frag");
- // specify texture for skybox
-// m_skyboxShader->bind();
-// glUniform1i(glGetUniformLocation(m_skyboxShader->id(), "cubeMap"), 9); // bind texture at slot 9
-// Eigen::Vector3f sc = Eigen::Vector3f(.77f, .85f, .99f); // skycolor for fade effect
-// glUniform3f(glGetUniformLocation(m_skyboxShader->id(), "skyColor"), sc[0], sc[1], sc[2]);
-// m_skyboxShader->unbind();
-
m_halftone_tex = loadTextureFromFile(":resources/images/halftone.png").textureID;
m_foam_tex = loadTextureFromFile(":resources/images/foam3.png").textureID;
@@ -438,36 +431,33 @@ void GLWidget::paintGL()
// m_arap.draw(m_pointShader, GL_POINTS);
// m_pointShader->unbind();
-// m_foamShader->bind();
-// m_foamShader->setUniform("proj", m_camera.getProjection());
-// m_foamShader->setUniform("view", m_camera.getView());
-//// m_foamShader->setUniform("vSize", m_vSize);
-//// m_foamShader->setUniform("width", width());
-//// m_foamShader->setUniform("height", height());
-// glUniform1f(glGetUniformLocation(m_foamShader->id(), "time"), m_arap.getTime());
-// glUniform1f(glGetUniformLocation(m_foamShader->id(), "phaseC"), 1.f);
-// m_foamShader->setUniform("widthBounds", m_arap.minCorner[0], m_arap.maxCorner[0]);
-// m_foamShader->setUniform("lengthBounds", m_arap.minCorner[2], m_arap.maxCorner[2]);
-//
-// glActiveTexture(GL_TEXTURE5);
-// glBindTexture(GL_TEXTURE_2D, m_halftone_tex);
-// glUniform1i(glGetUniformLocation(m_foamShader->id(), "halftone_texture"), 5);
-//
-// glActiveTexture(GL_TEXTURE6);
-// glBindTexture(GL_TEXTURE_2D, m_foam_tex);
-// glUniform1i(glGetUniformLocation(m_foamShader->id(), "foam_texture"), 6);
+ m_foamShader->bind();
+ m_foamShader->setUniform("proj", m_camera.getProjection());
+ m_foamShader->setUniform("view", m_camera.getView());
+ glUniform1f(glGetUniformLocation(m_foamShader->id(), "time"), m_arap.getTime());
+ glUniform1f(glGetUniformLocation(m_foamShader->id(), "phaseC"), 1.f);
+ m_foamShader->setUniform("widthBounds", m_arap.minCorner[0], m_arap.maxCorner[0]);
+ m_foamShader->setUniform("lengthBounds", m_arap.minCorner[2], m_arap.maxCorner[2]);
+
+ glActiveTexture(GL_TEXTURE5);
+ glBindTexture(GL_TEXTURE_2D, m_halftone_tex);
+ glUniform1i(glGetUniformLocation(m_foamShader->id(), "halftone_texture"), 5);
+
+ glActiveTexture(GL_TEXTURE6);
+ glBindTexture(GL_TEXTURE_2D, m_foam_tex);
+ glUniform1i(glGetUniformLocation(m_foamShader->id(), "foam_texture"), 6);
+
+
+
+
+ m_arap.drawFoam(m_foamShader, GL_TRIANGLES);
+ m_foamShader->unbind();
+ // skybox
-// m_arap.drawFoam(m_foamShader, GL_TRIANGLES);
-// m_foamShader->unbind();
-//
-// // skybox
-//
-//
-//
-// m_skybox.draw(m_skyboxShader, m_camera);
+ m_skybox.draw(m_skyboxShader, m_camera);
@@ -477,25 +467,32 @@ TextureData GLWidget::loadTextureFromFile(const char *path)
{
std::string filename = std::string(path);
+ QString filepath = QString(filename.c_str());
+ QImage tex_image = QImage(filepath);
+ tex_image = tex_image.convertToFormat(QImage::Format_RGBA8888);
+ auto data = tex_image.bits();
+ int width = tex_image.width();
+ int height = tex_image.height();
+
GLuint textureID;
glGenTextures(1, &textureID);
- int width, height, nrComponents;
- stbi_set_flip_vertically_on_load(true);
- unsigned char *data = stbi_load(filename.c_str(), &width, &height, &nrComponents, 0);
- stbi_set_flip_vertically_on_load(false);
+// int width, height, nrComponents;
+// stbi_set_flip_vertically_on_load(true);
+// unsigned char *data = stbi_load(filename.c_str(), &width, &height, &nrComponents, 0);
+// stbi_set_flip_vertically_on_load(false);
if (data)
{
- GLenum format;
- if (nrComponents == 1)
- format = GL_RED;
- else if (nrComponents == 3)
- format = GL_RGB;
- else if (nrComponents == 4)
- format = GL_RGBA;
+// GLenum format;
+// if (nrComponents == 1)
+// format = GL_RED;
+// else if (nrComponents == 3)
+// format = GL_RGB;
+// else if (nrComponents == 4)
+// format = GL_RGBA;
glBindTexture(GL_TEXTURE_2D, textureID);
- glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@@ -503,13 +500,13 @@ TextureData GLWidget::loadTextureFromFile(const char *path)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- stbi_image_free(data);
+// stbi_image_free(data);
}
else
{
std::cout << "Texture failed to load at path: " << path << std::endl;
- stbi_image_free(data);
+// stbi_image_free(data);
}
TextureData newtex;
@@ -518,50 +515,6 @@ TextureData GLWidget::loadTextureFromFile(const char *path)
newtex.width = width;
return newtex;
}
-
-GLuint GLWidget::loadCubeMap(std::vector<const char*> textureFiles){
- std::cout << "hello 111" << std::endl;
-
- // create empty texture
- GLuint textureID;
- glGenTextures(1, &textureID);
-
- std::cout << "hello fssd" << std::endl;
-
-
- //glActiveTexture(GL_TEXTURE3);
- glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);
-
- glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
- glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER,GL_LINEAR);
- glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
-
- std::cout << "hello fssd" << std::endl;
-
- GLuint target = GL_TEXTURE_CUBE_MAP_POSITIVE_X;
- for (int i=0; i<6; i++){
- std::string filename = std::string(textureFiles[i]);//directory + '/' + filename;
- int width, height, nrChannels;
- unsigned char* data = stbi_load(filename.c_str(), &width, &height, &nrChannels, 0);
-
- if (data){
- stbi_set_flip_vertically_on_load(false);
- glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
- stbi_image_free(data);
-
- } else {
- std::cout << "Texture failed to load at path: " << textureFiles[i] << std::endl;
- stbi_image_free(data);
- }
- }
-
- return textureID;
-}
-
-
-
void GLWidget::resizeGL(int w, int h)
{
glViewport(0, 0, w, h);
diff --git a/src/glwidget.h b/src/glwidget.h
index d992ab6..60cca66 100755
--- a/src/glwidget.h
+++ b/src/glwidget.h
@@ -53,7 +53,6 @@ private:
void paintCaustics();
TextureData loadTextureFromFile(const char *path);
- GLuint loadCubeMap(std::vector<const char*> textureFiles);
private slots:
diff --git a/src/ocean/ocean_alt.cpp b/src/ocean/ocean_alt.cpp
index 0e44d9c..dcc3e42 100644
--- a/src/ocean/ocean_alt.cpp
+++ b/src/ocean/ocean_alt.cpp
@@ -589,7 +589,7 @@ std::vector<Eigen::Vector2d> ocean_alt::fast_fft
}
// divide by N*N and add the signs based on the indices
- double sign[] = {1.0, -1.0};
+ double sign[] = {-1.0, 1.0};
for (int i = 0; i < N; i++)
{
h[i] /= N;
diff --git a/src/ocean/ocean_alt.h b/src/ocean/ocean_alt.h
index dc8888d..9c5e4e2 100644
--- a/src/ocean/ocean_alt.h
+++ b/src/ocean/ocean_alt.h
@@ -42,6 +42,9 @@ public:
return m_foam_constants;
}
+ std::vector<Eigen::Vector3f> m_vertices; // current displacement vector for each K
+
+
@@ -71,8 +74,8 @@ private:
const int num_rows = 256;
const int num_cols = 256;
- const int num_tiles_x = 2;
- const int num_tiles_z = 2;
+ const int num_tiles_x = 1;
+ const int num_tiles_z = 1;
const double vertex_displacement = Lx / 2;
@@ -106,7 +109,6 @@ private:
int iterations = 0;
- std::vector<Eigen::Vector3f> m_vertices; // current displacement vector for each K
const double D = 1.0; // Depth below mean water level (for dispersion relation)
diff --git a/src/skybox.cpp b/src/skybox.cpp
index 3b894bd..70af2ce 100644
--- a/src/skybox.cpp
+++ b/src/skybox.cpp
@@ -69,25 +69,9 @@ void skybox::draw(Shader *skybox_shader, Camera m_camera){
// apply rotation matrix
skybox_shader->setUniform("rotation", m_rotation_mat);
- //glUniformMatrix4fv(glGetUniformLocation(skybox_shader., "rotation"), 1, GL_FALSE, glm::value_ptr(m_rotation_mat->getRotation()[0]));
-
- //Global::graphics.setGlobalData(glm::vec3(.5f));
glBindVertexArray(VAO);
glDrawArrays(GL_TRIANGLES, 0, m_vertices.size());
-
-// glDrawElements(GL_TRIANGLES, m_vertices.size(), GL_UNSIGNED_INT, reinterpret_cast<GLvoid *>(0));
-// glBindVertexArray(0);
-//// glBindTexture(GL_TEXTURE_2D, 0);
-///
-///
-///
-///
-
- // std::cout << m_camera.getPosition() << std::endl;
-
- // sky_shape.draw(skybox_shader, GL_TRIANGLES);
-
glDepthFunc(GL_LESS);
@@ -98,12 +82,6 @@ void skybox::draw(Shader *skybox_shader, Camera m_camera){
void skybox::update(double deltaTime){
m_rotation += ROTATE_SPEED * deltaTime;
-// Eigen::Rotation2Df f = Eigen::Rotation2Df(m_rotation);
-
-
-// m_rotation_mat = f.toRotationMatrix();
-
-
auto sinA = std::sin(m_rotation / 2);
auto cosA = std::cos(m_rotation/ 2);
@@ -119,12 +97,6 @@ void skybox::update(double deltaTime){
m_rotation_mat = mat4;
-
-
-
-
-
-
}
GLuint skybox::loadCubeMap(std::vector<const char*> textureFiles){
@@ -132,7 +104,7 @@ GLuint skybox::loadCubeMap(std::vector<const char*> textureFiles){
GLuint textureID;
glGenTextures(1, &textureID);
- // std::cout << "hello fssd" << std::endl;
+ std::cout << "hello fssd" << std::endl;
//glActiveTexture(GL_TEXTURE3);
@@ -144,22 +116,24 @@ GLuint skybox::loadCubeMap(std::vector<const char*> textureFiles){
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
- // std::cout << "hello fssd" << std::endl;
GLuint target = GL_TEXTURE_CUBE_MAP_POSITIVE_X;
for (int i=0; i<6; i++){
+ std::cout << i << std::endl;
std::string filename = std::string(textureFiles[i]);//directory + '/' + filename;
- int width, height, nrChannels;
- unsigned char* data = stbi_load(filename.c_str(), &width, &height, &nrChannels, 0);
+
+ QString sky_texture_filepath = QString(filename.c_str());
+ QImage box_image = QImage(sky_texture_filepath);
+ box_image = box_image.convertToFormat(QImage::Format_RGBA8888);
+ auto data = box_image.bits();
+ int width = box_image.width();
+ int height = box_image.height();
if (data){
- stbi_set_flip_vertically_on_load(false);
- glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
- stbi_image_free(data);
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
} else {
- // std::cout << "Texture failed to load at path: " << textureFiles[i] << std::endl;
- stbi_image_free(data);
+ std::cout << "Texture failed to load at path: " << textureFiles[i] << std::endl;
}
}