Commit 197e13de55e14aa0734f9ad8d8418bc6244eb9cb

Authored by Pavel Govyadinov
1 parent 32504c2c

Added new class gl_texture

contains the methods necessary for creating the gl texture and storing the texture ID, as well as retreiving it.
(not tested).
Showing 1 changed file with 104 additions and 0 deletions   Show diff stats
gl/gl_texture.h 0 → 100644
  1 +#ifndef STIM_GL_TEXTURE_H
  2 +#define STIM_GL_TEXTURE_H
  3 +
  4 +
  5 +#include <math.h>
  6 +#include <iostream>
  7 +#include <iterator>
  8 +#include <vector>
  9 +#include <algorithm>
  10 +#include "../parser/filename.h"
  11 +#include "../grids/image_stack.h"
  12 +#include <GL/glut.h>
  13 +#include <GL/glext.h>
  14 +
  15 +namespace stim{
  16 +
  17 +template<typename T>
  18 +class texture : public image_stack<T, 4>
  19 +{
  20 + protected:
  21 + std::string path
  22 + GLuint texID;
  23 +
  24 + public:
  25 +
  26 + //basic constructor
  27 + texture()
  28 + {}
  29 +
  30 + //path constructor
  31 + texture(std::string file_path){
  32 + path = file_path;
  33 + }
  34 +
  35 + //sets the path for the instance of texture.
  36 + void
  37 + setPath(std::string file_path)
  38 + {
  39 + path = file_path;
  40 + }
  41 +
  42 + //returns the path attached to the instance of texture.
  43 + std::string
  44 + getPath()
  45 + {
  46 + return path;
  47 + }
  48 +
  49 + GLuint
  50 + getTexture
  51 + {
  52 + return texID
  53 + }
  54 +
  55 + void
  56 + createTexture()
  57 + {
  58 + image_stack<T, 4>::load_images(path);
  59 + glGenTextures(1, &texID);
  60 + glBindTexture(GL_TEXTURE_3D, texID);
  61 + glTexParameteri(GL_TEXTURE_3D,
  62 + GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  63 + glTexParameteri(GL_TEXTURE_3D,
  64 + GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  65 + glTexParameteri(GL_TEXTURE_3D,
  66 + GL_TEXTURE_WRAP_S, GL_REPEAT);
  67 +
  68 + glTexParameteri(GL_TEXTURE_3D,
  69 + GL_TEXTURE_WRAP_S, GL_REPEAT);
  70 + glTexParameteri(GL_TEXTURE_3D,
  71 + GL_TEXTURE_WRAP_T, GL_REPEAT);
  72 + glTexParameteri(GL_TEXTURE_3D,
  73 + GL_TEXTURE_WRAP_R, GL_REPEAT);
  74 +
  75 + glTexImage3D(GL_TEXTURE_3D,
  76 + 0,
  77 + GL_RGB8,
  78 + R[1],
  79 + R[2],
  80 + R[3],
  81 + 0,
  82 + GL_RGBA,
  83 + GL_UNSIGNED_BYTE,
  84 + ptr);
  85 + //GL_UNSIGNED_BYTE can be TYPES, convert to GL equivalents
  86 + }
  87 + //Binds the texture
  88 + void
  89 + Bind()
  90 + {
  91 + glBindTexture(GL_TEXTURE_3D, texID);
  92 + }
  93 +
  94 + //add methods for handling the cases of T and conver them to GL equivalent.
  95 +
  96 + }
  97 +}
  98 +
  99 +
  100 +
  101 +
  102 +
  103 +
  104 +#endif
... ...