Advertisement

My Viewing Problem

Started by June 14, 2003 04:11 PM
3 comments, last by Xiachunyi 21 years, 8 months ago
Hello, I''ve been working on my game for quite some time and have arrived at some problems that have cirumvented me. I chose to ignore them until today, because of picking problems, but anyway are now biting me back. It seems that I have made the game to where it has a set viewing dimension that isn''t exactly matched up with what the program is drawing to. Example: Without resizing the screen

--------------------------------------- PSEUDO BOUNDRY
|                                      |
--------------------------------------- REAL BOUNDRY
|                                      |
|                                      |
|                                      |
--------------------------------------- PSEUDO BOUNDRY
|                                      |
--------------------------------------- REAL BOUNDRY
 
As you can see from my crude drawing that the real boundry is shifted some ways down than what it is really showing. I have identitfied this not only when I resize my Opengl API app but when I initiate Opengl selection. Now what I mean is that the object is not really where it appears to be. In my game, I have added opengl selection where the object being drawn is given an ID. If I click on that object then a message box pops up telling me that I have chosen that object. Without the resizing, if I click in the pseudo area of the projected object, no box pops up, but if I select an area within the real boundry the box pops up. After resizing the window screen, the projected and real boundries are aligned and therefore when there is no object in the proximity of the object, no message box, if I click on the object the box shows up. You can apply this to edge selection, with no resizing it does not show up on the upper corners, and only pops up about 1/4 of the way in the object from the top. From the bottom, it extends to almost the edge of the window ALTHOUGH the object is not there. If I resize it, then all is happy! With Resizing

---------------------------------------- REAL BOUNDRY AND SHOWN
|                                      |
|                                      |
|                                      |
|                                      |
|                                      |
|                                      |
---------------------------------------- REAL BOUNDRY AND SHOWN
 
You can after I have resized that what is projected to me and what the boundry that the computer has specified is lined up. Here is my opengl ini syntax:

int InitGL(GLvoid)
{
	if (!LoadGLTextures())
	{
		return FALSE;
	}
    load_settings();
    glEnable(GL_TEXTURE_2D);
  	gluPerspective(45.0f,(float)g_rRect.right/(float)g_rRect.bottom,0.1f,150.0f);
	glShadeModel(GL_SMOOTH);
	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
	glClearDepth(1.0f);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	glHint(GL_POINT_SMOOTH_HINT,GL_NICEST);
	glEnable(GL_LIGHT0);
	if(GL_LIGHTS)
	{
	    glEnable(GL_LIGHTING);
        glEnable(GL_COLOR_MATERIAL);
    }
	main_menu=GetMenu(hwnd);
	menu=CreatePopupMenu();	
	AppendMenu(menu,MF_STRING,ID_ACTION_ENDT,"End Turn");
	AppendMenu(menu,MF_STRING,ID_POP_INFO,"Status/Info");
	AppendMenu(menu,MF_STRING,ID_POP_CAST,"Cast Spell");
    AppendMenu(menu,MF_STRING,ID_POP_ORDER,"Issue Order");
    BuildFont_1();
    BuildFont_2();
    srand(time(NULL));
    start_game();
    if(SHOW_SPLASH)
    {
        DestroyWindow(splash);
    }
	return TRUE;
}
Here is my resizing syntax:

GLvoid ReSizeGLScene(GLsizei width, GLsizei height)
{
	if (height==0)
	{
		height=1;
	}
	glViewport(0,0,width,height);
	w=width;
	h=height;
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
  	gluPerspective(45.0f,(float)width/(float)height,0.1f,150.0f);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}
I have tried to insert the resizing syntax into my inialization, and although it aligns the projected boundry closer to the actual boundry, it is not close enough to be sufficient. I''ll probably upload some pictures of it before and after resizing after I get off from work. Thanks a lot even if you got this far. P.S. If I can''t figure it out in the next couple of days, I''ll issue a resize command from my original dimensions to about a couple of pixels in either direction and return it to 640X480 thereby correcting it.
errr...you''re not in PROJECTION matrix in your init function, right?
Advertisement
I''m in the default matrix, whatever was specified "Defaultly" when the no matrix was specified. I tried including the resizing syntax in my inilization function but it did absolutly nothing. So, I decided to take the cheap and dirty way out:
    SetWindowPos(hwnd,HWND_TOP,0,0,640,480,SWP_FRAMECHANGED);    SetWindowPos(hwnd,HWND_TOP,0,0,640,510,SWP_FRAMECHANGED); 

Something is passed into the resizing routine that I do not know about. Using the above syntax seems to correct it by resizing it automatically from one size to another and back to about the same size as the when it first showed. I even tried calling my WinMain Proc manually but that only successed in making my application look "wierd". So I just used the above code. One of these days I''ll find out what happened; until then, I''ll stick with this cheap trick. Thanks for listening to my constant ranting.
well, adding 4 lines of code to test it won''t kill you...

glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(45.0f,(float)width/(float)height,0.1f,150.0f);glMatrixMode(GL_MODELVIEW);glLoadIdentity();
Yea, I did try that in the inilization, but it seemed to do nothing at all. I had to resize the entire app to get it to display correctly. I guess I''ll go back and check how I''m drawing my objects, maybe there is a sneaky line of code somewhere in there.

This topic is closed to new replies.

Advertisement