skybox.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2020 Intel Corporation. All Rights Reserved.
3 
4 #include "skybox.h"
5 
6 #include <stb_image.h>
7 
8 #include "res/nx.h"
9 #include "res/ny.h"
10 #include "res/nz.h"
11 #include "res/px.h"
12 #include "res/py.h"
13 #include "res/pz.h"
14 
16 {
17  plus_x = nullptr;
18  plus_y = nullptr;
19  plus_z = nullptr;
20 
21  minus_x = nullptr;
22  minus_y = nullptr;
23  minus_z = nullptr;
24 }
25 
26 void skybox::render(rs2::float3 cam_position)
27 {
28  auto init = [](const uint8_t* buff, int length, std::shared_ptr<rs2::texture_buffer>& tex){
29  if (tex) tex.reset();
30  tex = std::make_shared<rs2::texture_buffer>();
31  int x, y, comp;
32  auto data = stbi_load_from_memory(buff, length, &x, &y, &comp, 3);
33  tex->upload_image(x, y, data, GL_RGB);
35  };
36  if (!initialized)
37  {
44  initialized = true;
45  }
47 
48  glColor3f(1.f, 1.f, 1.f);
49 
50  const auto r = 50.f;
51  const auto re = 49.999f;
52 
53  glTranslatef(cam_position.x, cam_position.y, cam_position.z);
54 
55  glBindTexture(GL_TEXTURE_2D, plus_z->get_gl_handle());
57  {
58  glTexCoord2f(0.f, 1.f); glVertex3f(-r, r, re);
59  glTexCoord2f(0.f, 0.f); glVertex3f(-r, -r, re);
60  glTexCoord2f(1.f, 1.f); glVertex3f(r, r, re);
61  glTexCoord2f(1.f, 0.f); glVertex3f(r, -r, re);
62  }
63  glEnd();
64 
65  glBindTexture(GL_TEXTURE_2D, minus_z->get_gl_handle());
67  {
68  glTexCoord2f(1.f, 1.f); glVertex3f(-r, r, -re);
69  glTexCoord2f(1.f, 0.f); glVertex3f(-r, -r, -re);
70  glTexCoord2f(0.f, 1.f); glVertex3f(r, r, -re);
71  glTexCoord2f(0.f, 0.f); glVertex3f(r, -r, -re);
72  }
73  glEnd();
74 
75  glBindTexture(GL_TEXTURE_2D, minus_x->get_gl_handle());
77  {
78  glTexCoord2f(1.f, 0.f); glVertex3f(-re, -r, r);
79  glTexCoord2f(0.f, 0.f); glVertex3f(-re, -r, -r);
80  glTexCoord2f(1.f, 1.f); glVertex3f(-re, r, r);
81  glTexCoord2f(0.f, 1.f); glVertex3f(-re, r, -r);
82  }
83  glEnd();
84 
85  glBindTexture(GL_TEXTURE_2D, plus_x->get_gl_handle());
87  {
88  glTexCoord2f(0.f, 0.f); glVertex3f(re, -r, r);
89  glTexCoord2f(1.f, 0.f); glVertex3f(re, -r, -r);
90  glTexCoord2f(0.f, 1.f); glVertex3f(re, r, r);
91  glTexCoord2f(1.f, 1.f); glVertex3f(re, r, -r);
92  }
93  glEnd();
94 
95 
96  glBindTexture(GL_TEXTURE_2D, minus_y->get_gl_handle());
98  {
99  glTexCoord2f(0.f, 0.f); glVertex3f(-r, re, r);
100  glTexCoord2f(0.f, 1.f); glVertex3f(-r, re, -r);
101  glTexCoord2f(1.f, 0.f); glVertex3f(r, re, r);
102  glTexCoord2f(1.f, 1.f); glVertex3f(r, re, -r);
103  }
104  glEnd();
105 
106  glBindTexture(GL_TEXTURE_2D, plus_y->get_gl_handle());
108  {
109  glTexCoord2f(0.f, 1.f); glVertex3f(-r, -re, r);
110  glTexCoord2f(0.f, 0.f); glVertex3f(-r, -re, -r);
111  glTexCoord2f(1.f, 1.f); glVertex3f(r, -re, r);
112  glTexCoord2f(1.f, 0.f); glVertex3f(r, -re, -r);
113  }
114  glEnd();
115 
117 
119 
120  glTranslatef(-cam_position.x, -cam_position.y, -cam_position.z);
121 }
static uint32_t cubemap_nx_png_size
Definition: nx.h:5
GLint y
#define GL_QUAD_STRIP
#define GL_TEXTURE_2D
static uint8_t cubemap_pz_png_data[]
Definition: pz.h:6
static uint32_t cubemap_ny_png_size
Definition: ny.h:5
#define glBegin
static uint8_t cubemap_nx_png_data[]
Definition: nx.h:6
STBIDEF stbi_uc * stbi_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp)
unsigned char uint8_t
Definition: stdint.h:78
#define glVertex3f
#define glEnable
static uint8_t cubemap_py_png_data[]
Definition: py.h:6
GLdouble f
std::shared_ptr< rs2::texture_buffer > plus_y
Definition: skybox.h:17
GLdouble GLdouble r
GLdouble x
std::shared_ptr< rs2::texture_buffer > plus_z
Definition: skybox.h:18
void render(rs2::float3 cam_position)
Definition: skybox.cpp:26
#define glTranslatef
std::shared_ptr< rs2::texture_buffer > minus_z
Definition: skybox.h:18
std::shared_ptr< rs2::texture_buffer > minus_x
Definition: skybox.h:16
void init(void)
Definition: boing.c:180
#define glEnd
std::shared_ptr< rs2::texture_buffer > plus_x
Definition: skybox.h:16
#define glTexCoord2f
static uint32_t cubemap_pz_png_size
Definition: pz.h:5
bool initialized
Definition: skybox.h:19
static uint8_t cubemap_px_png_data[]
Definition: px.h:6
#define glColor3f
std::shared_ptr< rs2::texture_buffer > minus_y
Definition: skybox.h:17
static uint8_t cubemap_nz_png_data[]
Definition: nz.h:6
static uint8_t cubemap_ny_png_data[]
Definition: ny.h:6
#define glBindTexture
skybox()
Definition: skybox.cpp:15
STBIDEF void stbi_image_free(void *retval_from_stbi_load)
static uint32_t cubemap_nz_png_size
Definition: nz.h:5
GLenum GLuint GLenum GLsizei length
#define GL_RGB
Definition: parser.hpp:150
static uint32_t cubemap_py_png_size
Definition: py.h:5
#define glDisable
static uint32_t cubemap_px_png_size
Definition: px.h:5


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:41