Windows and Opengl help..

Started by
0 comments, last by fishleg003 17 years, 6 months ago
Basically im trying to create an interface using the windows api and opengl to display the graphics so i can have a file menu at the top etc.. Hard for me to explain this only just begun to learn the basics of the api but this is what ive gathered so far.. Heres my main loop,
	hdc = GetDC(hwnd);
	EnableOpenGL(hwnd, &hdc, &hrc);
	while(!Done)
	{
		if(!PeekMessage( &msg, NULL, 0, 0, PM_REMOVE )){ //if no messages then redraw window
			UpdateWindow(hwnd);
		}
		else{
			if(msg.message == WM_QUIT)
				Done = true;
		}

		TranslateMessage(&msg); //translate keyboard messages 
		DispatchMessage(&msg); //sends the message to our window procedure message handler		
	}
	DisableOpenGL(hwnd, hdc, hrc); 




So here i thought if windows is not processing any messages then draw the window a sort of idle msg is that right ? Then in my message handler function i thought i would do something like,

switch(message)
	{
	case WM_PAINT:
		GetClientRect(hwnd, &rect); //gets the current dimensions of the window

		DrawText(hdc, TEXT("Some text in the middle of the screen!!"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER); //draw some text in the center of the screen

			glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
			glClear( GL_COLOR_BUFFER_BIT );
			
			glPushMatrix();
			glBegin( GL_TRIANGLES );
			glColor3f( 1.0f, 0.0f, 0.0f ); glVertex2f( 0.0f, 1.0f );
			glColor3f( 0.0f, 1.0f, 0.0f ); glVertex2f( 0.87f, -0.5f );
			glColor3f( 0.0f, 0.0f, 1.0f ); glVertex2f( -0.87f, -0.5f );
			glEnd();
			glPopMatrix();
			
			SwapBuffers( hdc );
		return 0;
	break;
	}





My problem is the window is not refreshing properly because at the moment its drawing wierdly like if you move the window around you can see the window flashing black then drawing the triangle... As if its not taking into account the double buffering. Thx alot for any help. fishy.
Advertisement
Sorry solved this problem i was setting my windows class wrong.

wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH ); //flashy flashywc.hbrBackground = NULL;//stops the background flashing :)


How do i overlay opengl and the windows api ive only draw text to the screen using this code below.
			glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );			glClear( GL_COLOR_BUFFER_BIT );						glPushMatrix();			glBegin( GL_TRIANGLES );			glColor3f( 1.0f, 0.0f, 0.0f ); glVertex2f( 0.0f, 1.0f );			glColor3f( 0.0f, 1.0f, 0.0f ); glVertex2f( 0.87f, -0.5f );			glColor3f( 0.0f, 0.0f, 1.0f ); glVertex2f( -0.87f, -0.5f );			glEnd();			glPopMatrix();				GetClientRect(hwnd, &rect); //gets the current dimensions of the window			DrawText(hdc, TEXT("hello butt fish"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER); //draw some text in the center of the screen					SwapBuffers( hdc );


If i do it this way the text appears on the screen but if you move the window around the text starts flashing so i cant be drawing it right, anyone know what could be causing that ?

This topic is closed to new replies.

Advertisement