Sign in to follow this  
fishleg003

OpenGL Windows and Opengl help..

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Sorry solved this problem i was setting my windows class wrong.


wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH ); //flashy flashy
wc.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 ?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this