Jump to content
  • Advertisement
Sign in to follow this  
fishleg003

OpenGL Windows and Opengl help..

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

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
Advertisement
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
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!