Say my texture has a size of 256x256 pixels. It contains 16 sub-textures of 64x64 pixels. Sub-textures should be displayed in quads. To increase performance, I want to transfer discrete values ββto a shader that encodes according to the coordinates of the vertex texture. For example, the values ββ0, 1, 2, 3 should correspond to (0.64), (64.64), (64.0), (0.0) by the coordinates of the vertex texture, etc.
Here is what I still have.
I load and bind the mipmap texture:
glGenTextures(1, &texture[0]); glBindTexture(GL_TEXTURE_2D, texture[0]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); gluBuild2DMipmaps(GL_TEXTURE_2D,3,TextureImage[0]->w,TextureImage[0]->h,GL_RGB,GL_UNSIGNED_BYTE,TextureImage[0]->pixels);
Then I upload my data:
glGenVertexArrays(1, &VecArrObj); glBindVertexArray(VecArrObj); glGenBuffers(1, &VertexBO); glBindBuffer(GL_ARRAY_BUFFER, VertexBO); glBufferData(GL_ARRAY_BUFFER, sizeof(VertAndTex), VertAndTex, GL_STREAM_DRAW); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glVertexAttribPointer(0, 3, GL_SHORT, GL_FALSE, 0, 0); glVertexAttribPointer(1, 1, GL_SHORT, GL_FALSE, 0, (void*)TexOffset); glGenBuffers(1, &IndexBO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexBO); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Indx), Indx, GL_STREAM_DRAW);
Here the attributes are pre-assigned to myProgram using glBindAttribLocation. This is how I show my squares:
glUseProgram(myProgram); glBindVertexArray(VecArrObj); glDrawElements(GL_QUADS, 4, GL_UNSIGNED_SHORT, 0); glBindVertexArray(0); glUseProgram(0);
Now that the mipmap texture is constantly connected, it should be accessible from shaders. So far, my shaders looked like this.
Vertex shader:
#version 130 in vec4 posit; //attr=0 in short textu; //attr=1 uniform mat4 trafoMat; void main() { gl_Position = trafoMat * posit; gl_TexCoord[0] = gl_MultiTexCoord0; }
Fragment Shader:
If tex is set to zero. These shaders do not even acquire the entire texture, but only whole quatrains up to one color from the texture (I think this is the upper left corner of the pixel). Obviously, I donβt have much experience working with shaders. Basically, my question is: how do I change my shaders for the purposes described at the beginning? Please note: my equipment does not support glGenSamplers ()).