So I am creating my own sorta gl_engine from scratch. My goal is to be able to have different classes that define different shapes and how to draw them. I want each of these classes a class holding a texture, and a class holding a Shader program.
As of now I have a pretty boss shader loader!
However my texture loader… Is really not good. First of all even though I have downloaded many examples I don’t really understand how textures are passed to the gpu which makes things problematic. Furthermore I am having issues with a function that loads textures.
This is because I think I am supposed to call “glActiveTexture(GLenum)”. The problem is I dont know where to find the GLEnum without using values defined in glew.h. Could you please help me do this or work around it? BTW the only libraries I am using are glew.h, freeglut.h, and SOIL.h (however if their is a library that is better then SOIL that is open source I would be fine changing which library is in charge of file reading).
If you want I could also send you my VisualStudio Project.
Here is my code thank you for spending the time to look over it. Btw in the Texture.cpp I have made a comment block in the spot where I am confused:
//Texture.h
#pragma once
#include <map>
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include "GL\glew.h"
#include "GL\freeglut.h"
#include "SOIL.h"
class Texture
{
public:
Texture(std::string it);
~Texture();
void Load();
GLuint texID;
private:
int width;
int height;
int chanels;
std::string filename;
};
std::vector<Texture> Textures;
int Amm = 0;
//Texture.cpp
#include "Texture.h"
Texture::Texture(std::string it)
{
width = 0;
height = 0;
chanels = 0;
filename = it;
}
Texture::~Texture()
{
}
void Texture::Load()
{
GLubyte* piData = SOIL_load_image(filename.c_str(), &width, &height, &chanels, SOIL_LOAD_AUTO);
if (piData == NULL)
{
std::cerr << "Cannot load image: " << filename.c_str() << std::endl;
exit(EXIT_FAILURE);
}
//vertically flip the image on Y axis since it is inverted
int i, j;
for (j = 0; j * 2 < height; ++j)
{
int index1 = j * width * chanels;
int index2 = (height - 1 - j) * width * chanels;
for (i = width * chanels; i > 0; --i)
{
GLubyte temp = piData[index1];
piData[index1] = piData[index2];
piData[index2] = temp;
++index1;
++index2;
}
}
Amm += 1;
texID = (Amm);
glGenTextures(1, &texID);
GLenum tex GL_TEXTURE'AMM'
glActiveTexture(tex);
/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OBIOUSLY THIS LINE WONT WORK BUT IT IS SUPPOSED TO BE GL_TEXTURE0,
GL_TEXTURE1 as defined in glew.h as
#define GL_TEXTURE0 0x84C0
#define GL_TEXTURE1 0x84C1*/
//glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texID);
//Texture parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
//allocate texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, piData);
//Free soil data
SOIL_free_image_data(piData);
}
Thanks so much!
Also a couple extra questions.
- How are textures passed to the GPU?
- How can textures be stored in a theoretically small sized GLuint
- Any other functions that would be useful to have in my Texture class
- Do you think it will work?
- Thanks much!
- What functions would I need in order to give each texture class the option to have a Normal and Specular map? And would I load those in the same way as any other texture?