Jump to content
  • Advertisement
Sign in to follow this  
Ehrys

OpenGL Double Buffer Produces Single Buffer "style" Output

This topic is 4140 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

Sorry for long title but that's basically the problem I'm having.
PIXELFORMATDESCRIPTOR m_PixelFormatDescriptor = {
		sizeof(PIXELFORMATDESCRIPTOR),	// Size of structure
		1,								// Version, Always 1
		PFD_DRAW_TO_WINDOW |			// Support Window
		PFD_SUPPORT_OPENGL |			// Support OpenGL
		PFD_DOUBLEBUFFER,				// Support Double Buffer
		PFD_TYPE_RGBA,					// RGBA Colour Mode
		32,								// Attempt 32bit Colour Mode
		0, 0, 0, 0, 0, 0,				// Ignore Colour Bits (Not used)
		0,								// No Alpha Buffer
		0,								// Ignore Shift Bit
		0,								// No Accumulation Buffer
		0, 0, 0, 0,						// Ignore Accumulation Buffer
		16,								// 16bit Z-Buffer
		0,								// No Stencil Buffer
		0,								// No Auxilliary Buffer
		PFD_MAIN_PLANE,					// Main Drawing Plane
		0,								// Reserved
		0, 0, 0 };						// Ignore Layer Masks


That's my PFD. In order to create a Window, I do the following:
WNDCLASSEX	WindowClass;		// Windows Class Structure
	DWORD		dwExStyle;			// Window Extended Style
	DWORD		dwStyle;			// Window Style
	RECT		WindowRect;			// Grabs Rectangle Upper Left / Lower Right Values

	WindowRect.left = PositionX;				// Set Left Value
	WindowRect.right = PositionX + Width;		// Set Right Value To Requested Width
	WindowRect.top = PositionY;					// Set Top Value
	WindowRect.bottom = PositionY + Height;		// Set Bottom Value To Requested Height

	hInstance					= GetModuleHandle(NULL);

	WindowClass.cbSize			= sizeof(WNDCLASSEX);
	WindowClass.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	WindowClass.lpfnWndProc		= MessageHandler;
	WindowClass.cbClsExtra		= 0;
	WindowClass.cbWndExtra		= 0;
	WindowClass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
	WindowClass.hCursor			= LoadCursor(NULL, IDC_ARROW);
	WindowClass.hbrBackground	= NULL;
	WindowClass.lpszMenuName	= NULL;

	if(isParent)
		WindowClass.lpszClassName	= m_MasterWindow.ClassName();
	else
	{
		if(m_MasterWindow.Handle() == NULL)
		{
			(*ErrorMessage).ErrorNumber = 4;
			(*ErrorMessage).Message = L"No Parent Window Found.";
			return false;
		}
		
		NewChild.ParentHandle(m_MasterWindow.Handle());
		char sz_ChildClass[4];
		sprintf_s(sz_ChildClass, 4, "%d", m_ChildWindows.size());
		NewChild.ClassName((LPCWSTR)sz_ChildClass);
		WindowClass.lpszClassName	= NewChild.ClassName();
	}

	WindowClass.hInstance		= hInstance;
	WindowClass.hIconSm			= LoadIcon(NULL, IDI_APPLICATION);

	if(!RegisterClassEx(&WindowClass))
	{
		(*ErrorMessage).ErrorNumber = 1;
		(*ErrorMessage).Message = L"Could Not Register Window Class";
		return false;
	}

	if(isParent)
	{
		dwExStyle	= WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;			// Window Extended Style
		dwStyle		= WS_OVERLAPPEDWINDOW;
		
		m_MasterWindow.Handle(
			CreateWindowEx(	dwExStyle,							// Extended Style For The Window
							m_MasterWindow.ClassName(),						// Class Name
							L"Application",							// Window Title
							dwStyle |							// Defined Window Style
							WS_CLIPSIBLINGS |					// Required Window Style
							WS_CLIPCHILDREN,					// Required Window Style
							PositionX, PositionY,								// Window Position
							WindowRect.right - WindowRect.left,	// Calculate Window Width
							WindowRect.bottom - WindowRect.top,	// Calculate Window Height
							NULL,								// No Parent Window
							NULL,								// No Menu
							hInstance,							// Instance
							NULL)								// Dont Pass Anything To WM_CREATE
							);
		if(!m_MasterWindow.Handle())
		{
			(*ErrorMessage).ErrorNumber = 2;
			(*ErrorMessage).Message = L"Could Not Create Parent Window";
			UnregisterClass(m_MasterWindow.ClassName(), hInstance);
			return false;
		}
		
		InitialiseWindow(m_MasterWindow.Handle());
		ShowWindow(m_MasterWindow.Handle(), SW_SHOW);
		SetForegroundWindow(m_MasterWindow.Handle());						// Slightly Higher Priority
		SetFocus(m_MasterWindow.Handle());									// Sets Keyboard Focus To The Window
...


In order to Initialise the Window:
m_MasterWindow.DeviceContext(GetDC(WindowHandle));
		nPixelFormat = ChoosePixelFormat(m_MasterWindow.DeviceContext(), &m_PixelFormatDescriptor);
		SetPixelFormat(m_MasterWindow.DeviceContext(), nPixelFormat, &m_PixelFormatDescriptor);
		m_MasterWindow.RenderContext(wglCreateContext(m_MasterWindow.DeviceContext()));
		wglMakeCurrent(m_MasterWindow.DeviceContext(), m_MasterWindow.RenderContext());
		//wglMakeCurrent(m_WindowClass->DeviceContext(), m_WindowClass->RenderContext());
		return true;


And finally, in order to render...
static float angle = 0;

	m_WindowClass = (*m_WindowManager).GetMasterWindow();
	
	
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	glLoadIdentity();

	//angle = angle + 0.1f;
	if(angle >= 360.0f)
		angle = 0.0f;

	glTranslatef(0.0f, 0.0f, -5.0f);
	glRotatef(angle, 0.0f, 0.0f, 1.0f);

	glColor3f(1.0f, 0.0f, 0.0f);
	glBegin(GL_TRIANGLES);
		glVertex3f(0.0f, 0.0f, 0.0f);
		glVertex3f(1.0f, 0.0f, 0.0f);
		glVertex3f(1.0f, 1.0f, 0.0f);
	glEnd();

	SwapBuffers((*m_WindowClass).DeviceContext());


This produces a red triangle that is seperated by black lines, as though I have double buffering disabled. Could someone point me in the right direction please? This is annoying the hell out of me. :(

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!