PDA

View Full Version : using command glDrawPixels(), but no display...



reader1
04-15-2015, 02:48 AM
here is the copy of red guide example,

void makeTexturePic(void)
{
int i, j, c;

for (i = 0; i < TEXTUREWIDTH; i++) {
for (j = 0; j < TEXTUREHEIGHT; j++) {
c = (((i & 0x8) == 0) ^ ((j & 0x8) == 0)) * 255;
chessTexture[i][j][0] = (GLubyte) c;
chessTexture[i][j][1] = (GLubyte) c;
chessTexture[i][j][2] = (GLubyte) c;
}
}
}
void checkDisplay(){
glClear(GL_COLOR_BUFFER_BIT);
glDrawPixels(TEXTUREWIDTH,TEXTUREHEIGHT,GL_RGB, GL_UNSIGNED_BYTE,chessTexture);
glFlush();
glutSwapBuffers();
}

int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);

glutInitWindowSize(600,600);
glutInitWindowPosition(100,100);

glutCreateWindow("GLSL Test : Draw a triangle");

//glutReshapeFunc(reshape1);
glutDisplayFunc(checkDisplay);

glutKeyboardFunc(keyboard);

glutMainLoop();

return 0;
}
but display nothing, what's matter?

Mekrod
04-15-2015, 05:39 AM
why your function "makeTexturePic()" never used in example?

reader1
04-15-2015, 06:46 AM
why your function "makeTexturePic()" never used in example?
forget.
here it is,

void checkDisplay(){
glClear(GL_COLOR_BUFFER_BIT);
makeTexturePic();
glDrawPixels(TEXTUREWIDTH,TEXTUREHEIGHT,GL_RGB, GL_UNSIGNED_BYTE,chessTexture);
glFlush();
glutSwapBuffers();
}

reader1
04-16-2015, 08:06 AM
So it is the example 9.1, which is at
http://www.glprogramming.com/red/chapter09.html

void makeCheckImage(void)
{
int i, j, c;

for (i = 0; i < checkImageHeight; i++) {
for (j = 0; j < checkImageWidth; j++) {
c = ((((i&0x8)==0)^((j&0x8))==0))*255;
checkImage[i][j][0] = (GLubyte) c;
checkImage[i][j][1] = (GLubyte) c;
checkImage[i][j][2] = (GLubyte) c;
checkImage[i][j][3] = (GLubyte) 255;
}
}
}...

reader1
04-16-2015, 06:45 PM
In this example, there is a typo at
c = ((((i&0x8)==0)^((j&0x8))==0))*255; //extra ) error.

ater delete it, but show only one b/w box, what's matter?

reader1
04-16-2015, 06:56 PM
image appears at last, but only one side.
continue...

reader1
04-16-2015, 09:45 PM
as if the order of the statements can not be changed,
glGenTextures(1, &achTexture);
glBindTexture(GL_TEXTURE_2D, achTexture);
glTexImage2D(GL_TEXTURE_2D,0,3,TEXTUREWIDTH,
TEXTUREHEIGHT,0,GL_RGB,GL_UNSIGNED_BYTE,chessTextu re);
glPixelStorei(GL_UNPACK_ALIGNMENT,1);

else it will be only one side appearance.