CustusX  2023.01.05-dev+develop.0da12
An IGT application
texture.h
Go to the documentation of this file.
1 #ifndef TEXTURE_H
2 #define TEXTURE_H
3 
4 #include <stdio.h>
5 #include <string.h>
6 #include <iostream>
7 
8 //OpenGL
9 #include <GL/glew.h>
10 #include <glut.h> //Framework on Mac
11 
12 //------------------------------------------------------------------------------------
13 
14 #define MAX_TEXTURE_SIZE 1000
15 static unsigned char generated_texture[MAX_TEXTURE_SIZE];
16 //static float generated_texture[MAX_TEXTURE_SIZE];
17 
18 template <typename TYPE>
19 TYPE *generateTexture(unsigned int x, unsigned int y, unsigned int z,
20  TYPE red, TYPE green, TYPE blue, TYPE alpha,
21  bool debug=false)
22 {
23  int numberOfColorComponents = 4;
24  unsigned int data_size = x*y*z*numberOfColorComponents;
25 
26  if(data_size > MAX_TEXTURE_SIZE)
27  std::cout << "-----------------------> Error: trying to create texture bigger than the max size" << std::endl;
28 
29  for(int i=0; i<data_size; )
30  {
31  generated_texture[i++] = (TYPE)red;
32  generated_texture[i++] = (TYPE)green;
33  generated_texture[i++] = (TYPE)blue;
34  generated_texture[i++] = (TYPE)alpha;
35 
36  }
37 
38  if(debug)
39  {
40  std::cout.precision(3);
41  for(int i=0; i<data_size; ++i)
42  {
43  std::cout << ' ' << (TYPE) generated_texture[i];
44  }
45  std::cout << std::endl;
46  }
47 
48  return generated_texture;
49 };
50 
51 
52 //------------------------------------------------------------------------------------
53 
54 #endif // TEXTURE_H
#define MAX_TEXTURE_SIZE
Definition: texture.h:14
TYPE * generateTexture(unsigned int x, unsigned int y, unsigned int z, TYPE red, TYPE green, TYPE blue, TYPE alpha, bool debug=false)
Definition: texture.h:19