Window Creation in Win 7

Started by
29 comments, last by Dim_Yimma_H 8 years ago

//The docs say the second arg to glClearBufferfv should be GL_DRAW_BUFFERi to clear and if it is GL_NONE then the operation does nothing. GL_NONE = 0, which you use, so try using GL_DRAW_BUFFER0 instead of 0 as the second arg.(incorrect)

Also remember to remove the glClear after your if-statement so that you don't re-clear it to the default clear color again before swap.

You seem to run into many of these weird problems caused by small mistakes in the details. Make it a habit to read the docs for the functions you use if they don't work right away, as well as use the debugger to single-step through the code, which is extremely helpful to solve these problems a hundred times faster than posting on GD.net about them.

I like this site for GL docs: http://docs.gl/

Do you use Visual Studio? If you don't use the debugger then start doing so, by default just press F9 on a particular line of code and then F5 to run with the debugger and the debugger will break on that line, where you can single-step with F10 and inspect variables with mouse-over. Faster than ExitProcess and std::cout.

Advertisement

Is there a more standard or general way to create windows in C++ ?

http://www.glfw.org/ seems pretty good for somewhat minimal OpenGL windows. If you need more then look into Qt or some other UI toolkit.

Thanks again Erik!

Yes I do have trouble with the details. I've been wanting to do what I am doing now for years but never had the time. And I still don't :) But I am trying now anyway. I'll do my best to check and recheck the opengl and MSDN docs!

I really do appreciate all your help!

I've edited my code as below but still get a black screen... *sigh*


			if ((char*)glGetString(GL_VERSION) != NULL) {
				//glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //0.8956f, 0.3451f, 0.2234f, 1.0f
				glClearBufferfv(GL_COLOR, GL_DRAW_BUFFER0, red);
				//ExitProcess(100); //<--- THIS EXITPROCESS RUNS
			}
			else {
				//glClearColor(0.8956f, 0.3451f, 0.2234f, 1.0f); 
				glClearBufferfv(GL_COLOR, GL_DRAW_BUFFER0, red);
				//ExitProcess(100);
			}
			glClear(GL_COLOR_BUFFER_BIT);

			SwapBuffers(hDC);

glClearBufferfv and glClear both clear the buffer.. so glClear will overwrite glClearBufferfv with whatever color is set by glClearColor (defaults to black if glClearColor has never been called).

Now my code looks like this but still a black window


			// Draw
			if ((char*)glGetString(GL_VERSION) != NULL) {
				//glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //0.8956f, 0.3451f, 0.2234f, 1.0f
				glClearBufferfv(GL_COLOR, GL_DRAW_BUFFER0, red);
				//ExitProcess(100); //<--- THIS EXITPROCESS RUNS
			}
			else {
				//glClearColor(0.8956f, 0.3451f, 0.2234f, 1.0f); 
				glClearBufferfv(GL_COLOR, GL_DRAW_BUFFER0, red);
				//ExitProcess(100);
			}
			//glClear(GL_COLOR_BUFFER_BIT);

			SwapBuffers(hDC);

which begs the question, when SwapBuffers is called, Is it swapping in GL_DRAW_BUFFER0 ? and is it the same as GL_BACK and GL_FRONT as the msdn SwapBuffers doc page mentions...

There is probably some other error, itshould work... I pasted the code you posted on the first page into VS and commented out glClear and I saw a red window.

Actually I gave you incorrect information, deepest apologies. You should use 0 and not GL_DRAW_BUFFERi, I probably assumed there was an error in the call and read the docs wrong :( The problem all along must have been the second glClear.

You should remove that if() which does nothing, glGetString will never return NULL for version and it wouldn't make a difference anyway, if you want to change behavior on version you should use other comparison methods.

ok thanks!

No worries about trying to help! Again, very much appreciated!

I'll simplify the code and try "0" in place of GL_DRAW_BUFFER0 later today.

Thanks again!

This topic is closed to new replies.

Advertisement