PDA

View Full Version : Zeroed pixels of textures



Alex. S
08-29-2015, 12:37 AM
I create textures (for example, I just fill the texture color):


void LoadTexture(char TextureID, GLuint *Texture)
{
DWORD w, h;
GLubyte *Data;

if (TextureID == 0) {
w=512; h=512;
}
else {
w=128; h=64;
}

Data = new GLubyte[3 * w * h];

if (TextureID == 0)
memset(Data, 204, w * h * 3);
else
memset(Data, 102, w * h * 3);


glBindTexture(GL_TEXTURE_2D, Texture[TextureID]);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, Data);

delete [] Data;
}

int InitGL()
{
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

glEnable(GL_TEXTURE_2D);
Textures = new GLuint[2];
glGenTextures(2, Textures);
LoadTexture(0, Textures);
LoadTexture(1, Textures);

return TRUE;
}

and render their:


int glDraw()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

glBindTexture(GL_TEXTURE_2D, Textures[0]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex2f(0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex2f(512.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex2f(512.0f, 512.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex2f(0.0f, 512.0f);
glEnd();


glBindTexture(GL_TEXTURE_2D, Textures[1]);

glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex2f(128.0f, 64.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex2f(256.0f, 64.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex2f(256.0f, 128.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex2f(128.0f, 128.0f);
glEnd();

return TRUE;
}

But, after use glClear or glBindTexture, the N first pixels of texture can be zeroed:
20672068

Sometimes it may look normal:
2069