PDA

View Full Version : Nothing shown in VC++ 6.0, but is in Cygwin



Beluvius
04-20-2004, 01:06 PM
Hi all,

I am trying to write some cross-platform code, in which I update a texture by some software manipulation, and trying to display that texture each frame. I have not optimized the code yet, but I am seeing the following difference between Cygwin and VC++: in Cygwin, everything works as I am expecting, but in VC++ with the same code, nothing is shown. Ps: my texture is mainly black at the moment, and a black window is shown. If I display another (mainly white) texture, a white window is shown.
I am using glut for initialization and window creation.


void screeninit(void)
{
...
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &glTexNum);
glBindTexture(GL_TEXTURE_2D, glTexNum);
}

void screendraw(void)
{
glBindTexture(GL_TEXTURE_2D, glTexNum);
glTexImage2D(GL_TEXTURE_2D, 0, 3, aTextures[0].iSizeX, aTextures[0].iSizeY,
0, GL_RGB, GL_UNSIGNED_BYTE, aTextures[0].pData);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glBindTexture(GL_TEXTURE_2D, glTexNum);
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0);
glVertex2i(0, 0);
glTexCoord2f(1.0, 0.0);
glVertex2i(aTextures[0].iSizeX, 0);
glTexCoord2f(1.0,1.0);
glVertex2i(aTextures[0].iSizeX, aTextures[0].iSizeY);
glTexCoord2f(0.0, 1.0);
glVertex2i(0, aTextures[0].iSizeY);
glEnd();
glFlush();
}

For completeness, the glut initialization:
int prgRun(int x, int y)
{
int argc = 1;
char * argv[1] = { "test" };
glutInit(&argc, argv);
screeninit(x, y);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(0,0);
glutInitWindowSize(x, y);
glutCreateWindow("title");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(idle);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutPassiveMotionFunc(mousemove);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, x, 0, y, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glutMainLoop();
return 0;
}I am puzzled of why this goes wrong. As far as I know, the glEnable(GL_TEXTURE_2D) makes sure the texture is shown, and that works under Cygwin.
(I will try under Suse linux soon)

Thanks in advance,
Beluvius

cryoknight
04-21-2004, 08:27 PM
I believe you need to add
glutSwapBuffers() as the last line in your rendering function, since you have
GLUT_DOUBLE defined...
That means that your program is double buffered, so anything you draw is being rendered to the backbuffer. If you don't swap the backbuffer, it won't appear on the screen.

cryoknight
04-21-2004, 08:31 PM
You would probably also want this code:
-------------------
glTexImage2D(GL_TEXTURE_2D, 0, 3, aTextures[0].iSizeX, aTextures[0].iSizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, aTextures[0].pData);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-------------------
in your screen_init() function, since it only needs to be done once per texture.

04-21-2004, 11:28 PM
Hi,

I forgot to mention that I have the glutSwapBuffers in my draw function as well. Sorry.
Furthermore, I don't think I want to be doing the adding of the texture functions to screeninit, as it then copies the contents of the textures[0].pData to it's internal memory, and I will have to update that every frame, as I change the contents of textures[0].pData.

Anyway, it now works somehow. I am not completely sure why it does work now, I did not change any code of the drawing functions. Perhaps VC++ can not handle memory errors as well as Cygwin :-). I had a problem in another part of the code, which caused a memory overwrite of some other allocated area. Not good... But I am still puzzled of why it does work under Cygwin, as it is basically still run under Windows.

Thanks for the replies,
Beluvius