PeriDyno 1.0.0
Loading...
Searching...
No Matches
pictrue.cpp
Go to the documentation of this file.
1#include "picture.h"
2#define STB_IMAGE_IMPLEMENTATION
3#include "stb/stb_image.h"
4
5namespace dyno {
6 // Simple helper function to load an image into a OpenGL texture with common
7 // settings
8 bool Picture::LoadTextureFromFile(const char *filename, GLuint *out_texture,
9 int *out_width, int *out_height) {
10 // Load from file
11 int image_width = 0;
12 int image_height = 0;
13 unsigned char *image_data =
14 stbi_load(filename, &image_width, &image_height, NULL, 4);
15 if (image_data == NULL) return false;
16
17 // Create a OpenGL texture identifier
18 GLuint image_texture;
19 glGenTextures(1, &image_texture);
20 glBindTexture(GL_TEXTURE_2D, image_texture);
21
22 // Setup filtering parameters for display
23 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
24 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
25
26 // Upload pixels into texture
27 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
28 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image_width, image_height, 0,
29 GL_RGBA, GL_UNSIGNED_BYTE, image_data);
30 stbi_image_free(image_data);
31
32 *out_texture = image_texture;
33 *out_width = image_width;
34 *out_height = image_height;
35
36 return true;
37 }
38}
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
int image_height
Definition picture.h:13
bool LoadTextureFromFile(const char *filename, GLuint *out_texture, int *out_width, int *out_height)
Definition pictrue.cpp:8
int image_width
Definition picture.h:14