Advertisement

Mouse/Drawing problem

Started by January 25, 2002 12:43 PM
2 comments, last by Dunge 23 years, 1 month ago
I have a small w32 opengl engine and after doing everything I need I tested it and something strange happenned, I was abble to move my primitive (some quads/triangle) with the mouse on axis X and Z even if I didn''t had any code for it. Well I have in the message events the code to look on WM_MOUSEMOVE and WM_KEYDOWN (I think I didn''t made any mistake here). The MOUSEMOVE was just to stock position of the mouse into variables and KEYDOWN/KEYUP were to change color of my primitive.. so I asked on IRC and someone told me to put break; at the end of the WM_MOUSEMOVE select case because it would interfer with WM_KEYDOWN... even if I don''t understand and I hate to do things when I don''t understand, I tested and now.. humm well the problem have something to do with that because now it don''t draw anything anymore... But you can''t really help if you don''t have any idea of the code so tell me your e-mail if you wanna help, I will send it.. thx!
When you use switch statements, you must include "break;" at the end of each case. The reason for this is that once the program finds the correct case, it will execute the code from that point on until it reaches a break statement or the end of a code block.

  		case WM_KEYDOWN:							// Is A Key Being Held Down?		{			keys[wParam] = TRUE;					// If So, Mark It As TRUE			break;		}		case WM_KEYUP:								// Has A Key Been Released?		{			keys[wParam] = FALSE;					// If So, Mark It As FALSE			break;		}  


After my exam I said, "GG Professor".
After my exam I said, "GG Professor".
Advertisement
Yeah I know that but I don''t understand why it make my drawings move on axis X and Z when I move the mouse and why nothing appear anymore... ohh and.. I do return 0; then break;.. is it ok?
I'll post some code

  Main_Game_Loop(){	while(STATE!=STATE_EXIT)	{		switch(STATE)		{		case STATE_INIT:			{				if(!Racer.Init())				{					MessageBox(NULL, "Initilisation error", "Error", MB_OK);					STATE = STATE_EXIT;				}				else				{					STATE = STATE_MENU;				}			} break;		case STATE_MENU:			{				Racer.Messages();				Racer.Menu();			} break;//                ...some more states...         }    }    return 0;}  


The Racer.Init create a window with opengl on it and set all for it to look good

  void Racer::Messages(){	MSG msg;	while(PeekMessage(&msg,NULL,0,0,PM_REMOVE))	{	    TranslateMessage(&msg);	    DispatchMessage(&msg);	}}  


This only check messages

  LRESULT APIENTRY RacerProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam){	switch(msg)		{	//                ...some cases...		case WM_KEYDOWN:			{				keys[wParam] = TRUE;				return 0;			} break;		case WM_KEYUP:			{				keys[wParam] = FALSE;				return 0;			} break;		case WM_LBUTTONDOWN:			{			    mouse_x = LOWORD(lParam);          				mouse_y = HIWORD(lParam);				return 0;			} break;		case WM_MOUSEMOVE:			{	            mouse_x = LOWORD(lParam);          				mouse_y = HIWORD(lParam);				return 0;			} break;		default:break; 		} 	return DefWindowProc(hwnd, msg, wParam, lParam);}  


and them Racer.Menu (another .cpp)

        void Racer::Menu(){	if (FirstTime)		FirstLoad(); //create a display list and set up lights	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	glLoadIdentity();	glTranslatef(0.0f,0.0f,-6.0f);	glBegin(GL_QUADS);		glVertex3f(-1.0f, 1.2f, 0.0f);		glVertex3f( 1.0f, 1.2f, 0.0f);		glVertex3f( 1.0f, 0.8f, 0.0f);		glVertex3f(-1.0f, 0.8f, 0.0f);	glEnd();	SwapBuffers(hDC);	CheckMenuKeys();}  


and CheckMenuKeys :

  void CheckMenuKeys(void){//        ...lot of key checking (working)...}  


Humm it's a bit long, hope you will understand.. when I write // ...something... it's because I removed code because it wasn't needed to understand

Edited by - Dunge on January 25, 2002 6:59:46 PM

This topic is closed to new replies.

Advertisement