Jump to content
  • Advertisement
Sign in to follow this  
Jacob Jingle

Sampler array OpenGL(4.1)

This topic is 2553 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm just learning OpenGL(4.1) and GLSL(4.10) and I'm having a problem getting a my simple sampler array to work. The problem I'm having is that even know my "myTextureSampler[0]" is set to zero, I'm still getting the second texture. Shouldn't I only see it if my code is set like this 'myTextureSampler[1]'?

Thx ahead of time.

// frag
#version 410 core

in vec2 UV;
out vec3 out_Color;
uniform sampler2D myTextureSampler[2];

void main(void)
out_Color = texture2D(myTextureSampler[0], UV ).rgb;

//C++ setup code
std::array<GLuint, 2> m_textureID; // global

void LoadTextures()
Texture texture;
Texture texture2;

glGenTextures(2, &m_textureID[0]);

glBindTexture(GL_TEXTURE_2D, m_textureID.at(0));
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texture.m_infoHeader->biWidth,
texture.m_infoHeader->biHeight, 0, GL_BGR, GL_UNSIGNED_BYTE, &texture.m_vData.front());

glBindTexture(GL_TEXTURE_2D, m_textureID.at(1));
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texture2.m_infoHeader->biWidth,
texture2.m_infoHeader->biHeight, 0, GL_BGR, GL_UNSIGNED_BYTE, &texture2.m_vData.front());

const short BITMAP_MAGIC_NUMBER=19778;
const int RGB_BYTE_SIZE=3;

typedef struct tagBitmapFileHeader {
unsigned short bfType;
unsigned int bfSize;
unsigned short bfReserved1;
unsigned short bfReserved2;
unsigned int bfOffBits;
} BitmapFileHeader;
typedef struct tagBitmapInfoHeader {
unsigned int biSize;
int biWidth;
int biHeight;
unsigned short biPlanes;
unsigned short biBitCount;
unsigned int biCompression;
unsigned int biSizeImage;
int biXPelsPerMeter;
int biYPelsPerMeter;
unsigned int biClrUsed;
unsigned int biClrImportant;
} BitmapInfoHeader;

class Texture
int Load24BMP(TCHAR *file)
FILE *in = NULL; //file stream for reading
m_loaded = false; //bitmap is not loaded yet
// need fix unload if not loaded
//open the file for reading in binary mode
if(_tfopen_s(&in, file,_T("rb")) != 0)
return -1;

//if the file does not exist return in m_strError
return -2;

m_fileHeader = new BitmapFileHeader;
fread(&m_fileHeader->bfType, 2, 1, in);
fread(&m_fileHeader->bfSize, 4, 1, in);
fread(&m_fileHeader->bfReserved1, 2, 1, in);
fread(&m_fileHeader->bfReserved2, 2, 1, in);
fread(&m_fileHeader->bfOffBits, 4, 1, in);

//check for the magic number that says this is a bitmap
if(m_fileHeader->bfType != BITMAP_MAGIC_NUMBER)
return -3;

m_infoHeader = new BitmapInfoHeader;
fread(&m_infoHeader->biSize, 4, 1, in);
fread(&m_infoHeader->biWidth, 4, 1, in);
fread(&m_infoHeader->biHeight, 4, 1, in);
fread(&m_infoHeader->biPlanes, 2, 1, in);
fread(&m_infoHeader->biBitCount, 2, 1, in);
if(m_infoHeader->biBitCount != 24)
return -4;

fread(&m_infoHeader->biCompression, 4, 1, in);
//biSizeImage is rounded to next 4 byte boundary
//A0 37 F2 8B 31 C4 = A0 37 F2 8B 31 C4 00 00 in file
fread(&m_infoHeader->biSizeImage, 4, 1, in);
fread(&m_infoHeader->biXPelsPerMeter, 4, 1, in);
fread(&m_infoHeader->biYPelsPerMeter, 4, 1, in);
fread(&m_infoHeader->biClrUsed, 4, 1, in);
fread(&m_infoHeader->biClrImportant, 4, 1, in);

//make buffer big enough for data(with padding)

//read in the entire image

//close the file now that we have all the info


//3 Bytes = blue/green/red colors
unsigned int elements = m_infoHeader->biWidth * m_infoHeader->biHeight * 3;

//sticks data blue green red * Heightscale + Offset in tables
//Reformat(heightScale, offset);

//bitmap is now loaded
m_loaded = true;
//return success
return 1;
Dibs are upside down so flip it up
101 001
010 -> 010
001 101
void FlipDataUp()
// red/green/blue = 3 bytes
int pwidth = m_infoHeader->biWidth * 3;

//put rightside up due to fact image is upside down(not reversed)
std::vector<BYTE> buff;

for(int i = 0; i < m_infoHeader->biHeight; i++)
if(&m_vData[(m_infoHeader->biHeight * pwidth) - (pwidth + (pwidth * i))] == &m_vData[pwidth * i])

memmove(&buff[0], &m_vData[pwidth * i], pwidth);
memmove(&m_vData[pwidth * i], &m_vData[(m_infoHeader->biHeight * pwidth) - (pwidth + (pwidth * i))], pwidth);
memmove(&m_vData[(m_infoHeader->biHeight * pwidth) - (pwidth + (pwidth * i))], &buff[0], pwidth);
BMP image is rounded to next 4 byte boundary
A0 37 F2 8B 31 C4 = A0 37 F2 8B 31 C4 00 00 in file
So function removes 00 00
void RemovePadding()
// red/green/blue = 3 bytes
const unsigned int elements = m_infoHeader->biWidth * m_infoHeader->biHeight * 3;
const unsigned int padding = m_infoHeader->biSizeImage - elements;
const unsigned int paddperrow = padding / m_infoHeader->biHeight;
const int pwidth = m_infoHeader->biWidth * 3;

//remove padding
for(int i = 0; i < m_infoHeader->biHeight; i++)
memmove(&m_vData[pwidth * i], &m_vData[(pwidth * i) + (paddperrow * i)], pwidth);

bool m_loaded; //file loaded or not
std::vector<BYTE> m_vData; //buffer for bmp file data
unsigned int m_dataSize; //size of bmp file data buffer

BitmapFileHeader *m_fileHeader;

BitmapInfoHeader *m_infoHeader;

Share this post

Link to post
Share on other sites
Nevermind, I was using a tutorial that used Old Crappy Deprecated OpenGL and not the Shiney new version. :angry: (glBindSampler, glGenSamplers, glSamplerParameteri, glUniform1i(array[0], 0) and the like were the key)

I wish google would remove old deprecated opengl tutorial sites from their engine. They are the worst thing in the world when you're trying to learn everything.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!