Archived

This topic is now archived and is closed to further replies.

OpenGL Issues

This topic is 5377 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, i've been working on a very simple opengl template, based on nehe's oop code, for my applications. the problem i am having is when i try to render stuff in fullscreen opengl window, every thing is very wonky. Where as in windowed mode it works perfectly. i have looked over and over the code, not being able to find out what i did worng. If some of you may enlighten me. I have managed to narrow it down to OpenGL Initialization routine, at least thats where i think the problem is. few things to note in the code below, gfxWindow, and pTrace are 2 global variable/classes, gfxWindow contains all the window info, like resolution, bits per pixel, etc, where are pTrace is just a loging class that i use. And sorry if anyone thinks this is messy way of doing things, neat ness is not top of my priorities list
bool COpenGL::InitGL()
{
	pTrace->toFile("\nInitializing OpenGL States");
	
	glShadeModel(GL_SMOOTH);
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClearDepth(1.0f);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

	if (gfxWindow.winInit.bFullscreen)
	{
		pTrace->toFile("\n\tWindow is set to FullScreen mode");
	}
	else
		pTrace->toFile("\n\tWindow is set to Windowed mode");

	return true;
}

bool COpenGL::CreateGfxWindow()
{
	int			extGLError;
	GLuint		PixelFormat;
	WNDCLASSEX	wndClass;
	DWORD		dwExStyle;
	DWORD		dwStyle;
	
	wndClass.cbSize			= sizeof(wndClass);
	wndClass.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	wndClass.lpfnWndProc	= procWin;
	wndClass.cbClsExtra		= 0;
	wndClass.cbWndExtra		= 0;
	wndClass.hInstance		= gfxWindow.winInit.hInstance;
	wndClass.hIcon			= LoadIcon(gfxWindow.winInit.hInstance, IDI_APPLICATION);
	wndClass.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wndClass.hbrBackground	= NULL;
	wndClass.lpszMenuName	= NULL;
	wndClass.lpszClassName	= "Main Window";
	wndClass.hIconSm		= LoadIcon(NULL, IDI_WINLOGO);

	if (!RegisterClassEx(&wndClass))
	{
		pTrace->toFile("\n* Failed to Register the Window Class.");
		return false;
	}

	if (gfxWindow.winInit.bFullscreen)
	{
		pTrace->toFile("\n\tSetting dmScreenSettings values");
		DEVMODE dmScreenSettings;
		ZeroMemory(&dmScreenSettings, sizeof(DEVMODE));
		dmScreenSettings.dmSize			= sizeof(DEVMODE);
		dmScreenSettings.dmPelsHeight	= gfxWindow.winInit.iHeight;
		dmScreenSettings.dmPelsWidth	= gfxWindow.winInit.iWidth;
		dmScreenSettings.dmBitsPerPel	= gfxWindow.winInit.iBitDepth;
		dmScreenSettings.dmFields		= DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

		if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
		{
			pTrace->toFile("\n* Resolution of %d x %d is not supported.",gfxWindow.winInit.iWidth, gfxWindow.winInit.iWidth);
			return false;
		}
	}
	if (gfxWindow.winInit.bFullscreen)
	{
		pTrace->toFile("\n\tSetting dwExStyle values");
		dwExStyle	= WS_EX_TOPMOST;
		dwStyle		= WS_POPUP;
	}
	else
	{
		dwExStyle	= WS_EX_APPWINDOW |WS_EX_WINDOWEDGE;
		dwStyle		= WS_CAPTION;
	}

	static PIXELFORMATDESCRIPTOR pfd =				{
		sizeof (PIXELFORMATDESCRIPTOR),			
		1,
		PFD_DRAW_TO_WINDOW	|
		PFD_SUPPORT_OPENGL	|
		PFD_DOUBLEBUFFER,
		PFD_TYPE_RGBA,	
		gfxWindow.winInit.iBitDepth,
		0, 0, 0, 0, 0, 0,
		0,
		0,
		0,
		0, 0, 0, 0,
		16,
		0,
		0,
		PFD_MAIN_PLANE,
		0,
		0, 0, 0	
	};

	if (!(gfxWindow.hWnd = CreateWindowEx(dwExStyle, "Main Window", 
										gfxWindow.winInit.cTitle, 
										dwStyle | WS_CLIPSIBLINGS |WS_CLIPCHILDREN,
										0, 0, gfxWindow.winInit.iWidth, gfxWindow.winInit.iHeight,
										NULL, NULL, gfxWindow.winInit.hInstance, NULL)))
	{
		pTrace->toFile("\n* Window Creation ERROR.");
		KillWindow();
		return false;
	}
	
	if (!(gfxWindow.hDC = GetDC(gfxWindow.hWnd)))
	{
		pTrace->toFile("\n* Failed to create a GL Device Context");
		KillWindow();
		return false;
	}

	if (!(PixelFormat = ChoosePixelFormat(gfxWindow.hDC, &pfd)))
	{
		pTrace->toFile("\n* Can't find a suitable pixel format");
		KillWindow();
		return false;
	}

	if (!SetPixelFormat(gfxWindow.hDC, PixelFormat, &pfd))
	{
		pTrace->toFile("\n* Failed to Set Pixel Format");
		KillWindow();
		return false;
	}

	if (!(gfxWindow.hRC = wglCreateContext(gfxWindow.hDC)))
	{
		pTrace->toFile("\n* Can not create a GL Rendering Context");
		KillWindow();
		return false;
	}

	if (!wglMakeCurrent(gfxWindow.hDC, gfxWindow.hRC))
	{
		pTrace->toFile("\n* Cannot Activate the GL Rendering Context");
		KillWindow();
		return false;
	}

	extGLError = extgl_Initialize();
	if (extGLError != 0)
	{
		pTrace->toFile("\nExtGL exited with code %d", extGLError);
	}
	else
	{
		pTrace->toFile("\nCheck Supported GL Versions"); 
		if (extgl_Extensions.OpenGL12)
			pTrace->toFile("\n\tOpenGL 1.2 is Supported");
		if (extgl_Extensions.OpenGL13)
			pTrace->toFile("\n\tOpenGL 1.3 is Supported");
		if (extgl_Extensions.OpenGL14)
			pTrace->toFile("\n\tOpenGL 1.4 is Supported");
	}
	
	ShowWindow(gfxWindow.hWnd, SW_SHOW);
	SetForegroundWindow(gfxWindow.hWnd);
	SetFocus(gfxWindow.hWnd);
	ShowCursor(false);

	if(!InitGL())
	{
		pTrace->toFile("\nFailed to Initialize OpenGL Functions");
		KillWindow();
		return false;
	}
	pTrace->toFile("\nOpenGL Window Created");
	return true;
}
 
and in the window Proc i have this
		case WM_SIZE:
			if (height ==0)
				height =1;
			pTrace->toFile("\n+++Entered WM_SIZE");
			
			glViewport(0,0,width,height);
			glMatrixMode(GL_PROJECTION);
			glLoadIdentity();
			gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 0.1f, 500.0f);
			glMatrixMode(GL_MODELVIEW);
			glLoadIdentity();
			
			return 0;
 
[edited by - Roy Fokker on March 24, 2003 10:05:51 PM]

Share this post


Link to post
Share on other sites
I think you''re gonna have to elaborate on ''wonky''. Give a better description of the problem and even post some links of screenshots off the problem. Just by guessing about your problem (because you didn''t given enough info for me to deduce much more) and looking over your code real quick, I''ve never seen the flag WS_EX_TOPMOST ever used. Try taking that out and replacing it with WS_EX_APPWINDOW. That probably won''t help much tho...you''re just gonna more specific about ''wonky''.

-------------------
Realm Games Company

Share this post


Link to post
Share on other sites
1) What graphics card are you using?
2) What bitdepth are you setting the window to?
3) What bitdepth is your desktop set to?

I have found that unless my desktop bitdepth is set to 32 bit, MANY 3d programs run rediculously slow. I believe it has to do with using blending. Try settings your desktop bitdepth to 32 bit and see if it works any better. Also request 32 bit when you are creating the PFD.

Share this post


Link to post
Share on other sites
i have tried running program in 16 and 32 bit depths, set via the program it self

the results are like this
this is what it looks like in windowed mode (this is what it is supposed to look like)
Bit depth 32 bits, Window size 800x600
Windowed Screenshot

this is what it look like in full screen mode
same bitdepth and res
Fullscreen Screenshot
The vid card is not the problem, (i have GF3 latest drivers)
I experince the same problem with Nehe Lesson 3 tutorial, it works fine in windowed mode. but Fullscreen is very wonky



[edited by - Roy Fokker on March 25, 2003 9:48:21 AM]

Share this post


Link to post
Share on other sites
i have no switch between mode thing set up.

at the begining of the application, you get a simple dialog box with choices like resolution, bitdepth and where you want fullscreen or not.

which the application puts in the the gfxWindow(global) structure

and the application makes use of that, once its set you can't change during the course the application is running


[edited by - Roy Fokker on March 25, 2003 5:25:08 PM]

Share this post


Link to post
Share on other sites
Is your windows desktop running in the same bit-depth as your application ... I can tell you from experience that this is a common OpenGL problem, and is quite elusive. For many video cards, this has been an issue even for publicly released games ... ie Tribes / Tribes 2 actually stated (correctly) that you must set you desktop resolution to the correct depth, prior to running the program.

Obviously there is code that can fix this, which some programs use ... which I think involves setting the desktop disply with Win32 API functions, prior to registering your window class, and your opengl window, but I''m not sure.

Share this post


Link to post
Share on other sites
The only thing that makes me wonder is your case WM_SIZE section it doesn''t change you height and width variables when the window resizes. Try adding these lines right after case...

case WM_SIZE:
width = LOWORD(lParam);
height = HIWORD(lParam);
...

The rest of WM_SIZE looks fine...

I think that might fix your problem... Hope it helps!

Share this post


Link to post
Share on other sites
I agree with the above - it''s seems to be related to the sizing of the window.

Also, you should really set the depth bit in the PIXELFORMATDESCRIPTOR correctly. ie - use 16 or 24. On some older cards you might not get the results you''d expect. Although on newer cards this shouldn''t be a problem - I know that NV drivers will ignore a 16 bit depth with 32 bit color ... it''ll give you 24 bit depth.

Share this post


Link to post
Share on other sites
I have the
width = LOWORD(lParam);
height = HIWORD(lParam);

Just before winproc gets in to the switch case.

and as for the bit depth, its at 32bits, which is what i run the application at.

As for the PIXELFORMATDESCRIPTOR, i have it set to 16, but that has never cause this sort of problem before.
And i have tried using 24 as bit depth value. still get the same results

This is most infurating.
Well, just in case any one wants to see, the whole shabang, such as it is
Engine.zip
Its not very well commented.
and the controls for the camera are simple enough. arrow keys for xy plane, and Home and End for the Z-axis.

the solution uses VS.net format. but it think it should work on almost all windows compilers, with proper linker setups



[edited by - Roy Fokker on March 25, 2003 9:32:03 PM]

Share this post


Link to post
Share on other sites