UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
opengl_utils.cpp File Reference
#include <vector>
#include <string>
#include <stdexcept>
#include <cassert>
#include "opengl_utils.hpp"
#include "opengl_conversions.hpp"
#include "video_frame.h"
#include "video_codec.h"
#include "color.h"
#include "debug.h"
#include "host.h"
#include "utils/profile_timer.hpp"
Include dependency graph for opengl_utils.cpp:

Go to the source code of this file.

Macros

#define MOD_NAME   "[Opengl utils] "
 

Functions

bool check_gl_extension_present (const char *ext)
 
static void compileShader (GLuint shaderId)
 
static std::vector< unsigned > gen_sphere_indices (int latitude_n, int longtitude_n)
 
static std::vector< float > gen_sphere_vertices (int r, int latitude_n, int longtitude_n)
 

Variables

static const float PI_F =3.14159265358979f
 
static unsigned char pixels []
 
static const GLfloat rectangle []
 

Detailed Description

Macro Definition Documentation

◆ MOD_NAME

#define MOD_NAME   "[Opengl utils] "

Definition at line 52 of file opengl_utils.cpp.

Function Documentation

◆ check_gl_extension_present()

bool check_gl_extension_present ( const char * ext)

Definition at line 91 of file opengl_utils.cpp.

91 {
92 int count = 0;
93 glGetIntegerv(GL_NUM_EXTENSIONS, &count);
94
95 for(int i = 0; i < count; i++){
96 const char *item = (const char *) glGetStringi(GL_EXTENSIONS, i);
97 if(strcmp(item, ext) == 0)
98 return true;
99 }
100
101 return false;
102}
int count
Definition hd-rum.c:44
Definition hd-rum.c:27

References count.

◆ compileShader()

static void compileShader ( GLuint shaderId)
static

Definition at line 73 of file opengl_utils.cpp.

73 {
74 glCompileShader(shaderId);
75
76 GLint ret = GL_FALSE;
77 int len;
78
79 glGetShaderiv(shaderId, GL_COMPILE_STATUS, &ret);
80 glGetShaderiv(shaderId, GL_INFO_LOG_LENGTH, &len);
81 if (len > 0){
82 std::vector<char> errorMsg(len+1);
83 glGetShaderInfoLog(shaderId, len, NULL, &errorMsg[0]);
84 printf("%s\n", errorMsg.data());
85 }
86}
int void size_t * len

References len.

◆ gen_sphere_indices()

static std::vector< unsigned > gen_sphere_indices ( int latitude_n,
int longtitude_n )
static

Definition at line 470 of file opengl_utils.cpp.

470 {
471 std::vector<unsigned int> indices;
472
473 for(int i = 0; i < latitude_n; i++){
474 int slice_idx = i * (latitude_n + 1);
475 int next_slice_idx = (i + 1) * (latitude_n + 1);
476
477 for(int j = 0; j < longtitude_n; j++){
478 //Since the top and bottom slices are circles with radius 0,
479 //we only need one triangle for those
480 if(i != latitude_n - 1){
481 indices.push_back(slice_idx + j + 1);
482 indices.push_back(next_slice_idx + j);
483 indices.push_back(next_slice_idx + j + 1);
484 }
485
486 if(i != 0){
487 indices.push_back(slice_idx + j + 1);
488 indices.push_back(slice_idx + j);
489 indices.push_back(next_slice_idx + j);
490 }
491 }
492 }
493
494 return indices;
495}

Referenced by Model::get_sphere().

◆ gen_sphere_vertices()

static std::vector< float > gen_sphere_vertices ( int r,
int latitude_n,
int longtitude_n )
static

Definition at line 440 of file opengl_utils.cpp.

440 {
441 std::vector<float> verts;
442
443 float lat_step = PI_F / latitude_n;
444 float long_step = 2 * PI_F / longtitude_n;
445
446 for(int i = 0; i < latitude_n + 1; i++){
447 float y = std::cos(i * lat_step) * r;
448 float y_slice_r = std::sin(i * lat_step) * r;
449
450 //The first and last vertex on the y slice circle are in the same place
451 for(int j = 0; j < longtitude_n + 1; j++){
452 float x = std::sin(j * long_step) * y_slice_r;
453 float z = std::cos(j * long_step) * y_slice_r;
454 verts.push_back(x);
455 verts.push_back(y);
456 verts.push_back(z);
457
458 float u = 1 - static_cast<float>(j) / longtitude_n;
459 float v = static_cast<float>(i) / latitude_n;
460 verts.push_back(u);
461 verts.push_back(v);
462 }
463 }
464
465 return verts;
466}
static const float PI_F

References PI_F.

Referenced by Model::get_sphere().

Variable Documentation

◆ PI_F

const float PI_F =3.14159265358979f
static

Definition at line 54 of file opengl_utils.cpp.

Referenced by gen_sphere_vertices().

◆ pixels

unsigned char pixels[]
static
Initial value:
= {
255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 255,
255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 255,
255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 255,
255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 255
}

Definition at line 66 of file opengl_utils.cpp.

66 {
67 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 255,
68 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 255,
69 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 255,
70 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 255
71};

◆ rectangle

const GLfloat rectangle[]
static
Initial value:
= {
1.0f, 1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 0.0f, 1.0f,
-1.0f, -1.0f, 0.0f, 0.0f,
1.0f, 1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, 0.0f, 0.0f,
1.0f, -1.0f, 1.0f, 0.0f
}

Definition at line 56 of file opengl_utils.cpp.

56 {
57 1.0f, 1.0f, 1.0f, 1.0f,
58 -1.0f, 1.0f, 0.0f, 1.0f,
59 -1.0f, -1.0f, 0.0f, 0.0f,
60
61 1.0f, 1.0f, 1.0f, 1.0f,
62 -1.0f, -1.0f, 0.0f, 0.0f,
63 1.0f, -1.0f, 1.0f, 0.0f
64};