Beginner question about OpenGL problem

Started by
10 comments, last by kburkhart84 18 years, 1 month ago
I 'm sure this had been asked somewhere before, but I used the search, and was unable to find anyone with the same problem as me. Heres what I want to do: Create a 3d application that doesn't clear any buffers after each loop. glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ^-- Thats what I want to leave out. When I leave this out on the computers at my school, or on any other computer at my house, it does what I want it to do. Which is leave previously drawn pixels on the screen. On my computer, when I run the program, all of the static/lines/error-looking-stuff is in the window, flashing like crazy. I'm guessing its a problem with my graphics card or something, but I'm not sure. I have an Intel 82915G/GV/910GL Express Chipset Family Graphics card (I don't know if this information is helpful, but just in case...) On previous occasions, I just started out every OpenGL application with a black rotating quad that cleared whatever data seemed to be stuck where it didn't belong. But now I am running into situations where this won't be practical. I am using Dev-C++, and this problem occurs in the OpenGL template included with Dev-C++, and with the NeHe template I downloaded through the DevPacks sever. How do I fix this problem? (If necessary, I can post my source, although it's not much different than the templates.)
Advertisement
It's flashing like crazy because of double-buffering; one of the buffers is cleared, and the other one is filled with cruft. Disable double buffering, and all should be peachy.
Quote:Original post by Sneftel
It's flashing like crazy because of double-buffering; one of the buffers is cleared, and the other one is filled with cruft. Disable double buffering, and all should be peachy.


How exactly would I do that? I'm still new to this.

EDIT: Should I have put this in the OpenGL section? I just noticed there was one.
Double buffering is handled by Win32, SDL, GLut, or whatever else you are using to make the window. Tell us what you're using and we'll be able to help more.

Oh, and for a beginner question about OpenGL, both the OpenGL and For Beginners forumsare fine. Just flip a coin!
Quote:Original post by Ezbez
Double buffering is handled by Win32, SDL, GLut, or whatever else you are using to make the window. Tell us what you're using and we'll be able to help more.

Oh, and for a beginner question about OpenGL, both the OpenGL and For Beginners forumsare fine. Just flip a coin!


Thanks.

----------

void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC)
{
PIXELFORMATDESCRIPTOR pfd;
int iFormat;

/* get the device context (DC) */
*hDC = GetDC (hWnd);

/* set the pixel format for the DC */
ZeroMemory (&pfd, sizeof (pfd));
pfd.nSize = sizeof (pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; //-- Should I change this?
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 67;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
iFormat = ChoosePixelFormat (*hDC, &pfd);
SetPixelFormat (*hDC, iFormat, &pfd);

/* create and enable the render context (RC) */
*hRC = wglCreateContext( *hDC );
wglMakeCurrent( *hDC, *hRC );

}

----------

I think this is being handled by win32, but I'm not sure.
If you're using the NeHe template, in the main loop there should be a call to SwapBuffers, just comment out that line and it should work. (Because it never swaps to 2nd buffer)
Quote:Original post by Ganoosh_
If you're using the NeHe template, in the main loop there should be a call to SwapBuffers, just comment out that line and it should work. (Because it never swaps to 2nd buffer)


The only place I was able to find SwapBuffers was in NeHeGL.cpp, so I commented it out, and commented out glClear. Now all I get is a gray window.
I don't use NeHe base code, but doesn't the SwapBuffers() call also update the screen? Thats what most APIs do.
Quote:Original post by Ezbez
I don't use NeHe base code, but doesn't the SwapBuffers() call also update the screen? Thats what most APIs do.


Well, I Tried commenting out the SwapBuffers() in the Dev-C++ OpenGL template, and the screen was blank, and nothing happened.
You have to leave the initial glClear in. Also, if you aren't calling SwapBuffers, you may need to call glFinish after each frame. Also, of course, you need to remove the PFD_DOUBLEBUFFER attribute.

This topic is closed to new replies.

Advertisement