Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

NTense

Viewport Selection

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

OK, OpenGL has been busting my butt the last couple of days. I've created a Viewport class, and each instance of a viewport is stored in a List Template Container from the STL. At this point I'm feeling pretty good . But now, when multiple viewports are on the screen, I want to be able to make one the active viewport (designated by a black background), and the rest "inactive" (designated by a blue background). So, I created a boolean flag in the viewport class, and thought I could just do a bounding box check on where the mouse is being clicked. When I step through the code in the debugger, the viewports flags are set correctly, but they render incorrectly. If a bottom viewport is clicked on, the top one renders as active, and vise-versa. Left and right boundaries work correctly, but for some reason, the top and bottom one are rendering backwards (I say rendering backwards because their Active Flags are set correctly). Here's a screenshot of what the UI looks like and what's happening. And here's some of the source code:
WndProc
\/
\/
\/

// Here's all of my boundary checks, which seem to work fine

// when I step through the code.

case WM_LBUTTONDOWN:
	point.x = LOWORD(lParam);
	point.y = HIWORD(lParam);
			
	int x,y,maxx,maxy;
	
	// First Check if viewport is active, and if not, activate it

	// Iterate through the list of Viewports, and Display them


	for(itor = ViewList.begin(); itor != ViewList.end();itor++)
	{
		x = (*itor)->GetX();
		y = (*itor)->GetY();
		maxx = (*itor)->GetX()+(*itor)->GetWidth();
		maxy = (*itor)->GetY()+(*itor)->GetHeight(); 
			
		if(point.x >= x && point.x <= maxx && point.y <= maxy && point.y >= y)// )

		{
			(*itor)->SetActive(true);
		}
		else
		{
			(*itor)->SetActive(false);
		}
		
	}
	g_Redraw = true;
	return 0;
	break;

// here's my display function which iterates through the 

// list of viewports

void display(HWND hwnd)
{

	// Iterate through the list of Viewports, and Display them

	for(MXViewListItor itor = ViewList.begin(); itor != ViewList.end();itor++)
	{
		unsigned char testID = (*itor)->GetID();

		if(numViewports > 1 && (*itor)->IsActive()==false)
		{
			numViewports++;
			numViewports--;
		}
		(*itor)->Display();
	}

	glFlush();
	SwapBuffers(g_HDC);
	
	// Draw Seperators

	if (numViewports > 1)
		SendMessage(hwnd, WM_DRAWSEPERATORS, 0, 0);

	g_Redraw = false;
}

// Finally, here's my display function for the viewports

void MX_Viewport::Display()
{
	glEnable(GL_SCISSOR_TEST);
	glViewport(x,y, width, height);
	glScissor(x,y, width, height);

	glClearColor(BackgroundColor.GetR(), BackgroundColor.GetG(), BackgroundColor.GetB(), BackgroundColor.GetAlpha());// set to bg color

	
	
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 1.0f, 1000.0f);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	
	gluLookAt(position.GetX(), position.GetY(), position.GetZ(), target.GetX(), target.GetY(), target.GetZ(), 0.0, 1.0, 0.0);
	
	// Draw Stuff  Maybe traverse through a list of objects in the scene

	DrawGrid();
	testtriangle();
}
After wrestling with this for a couple of days, I'm hoping that someone here will see something that I'm overlooking.. Any help would be wonderful! Thanks. BTW: Ignore the FPS in the caption of the window . It's inaccurate because I'm limiting the drawing to only do so when there has been a change in the workspace. [edited by - NTense on March 5, 2004 5:05:57 PM]

Share this post


Link to post
Share on other sites
Advertisement
Well, it''s hard to tell. The problem is quite likely to you not tracking the areas of the viewports right, and the best guess I have without the code for how they are setup, would be that you''re using some opengl coordinates in the x,y calculation.

The reason I say that is in windows, 0,0 equates to the top left corner, whereas in opengl it''s the bottom left corner. It would explain why it works in reverse of what you might expect.

Share this post


Link to post
Share on other sites
Ah ha!! I believe you''re right! I completely forgot about OpenGL mapping from the bottom left. Now it all makes since.. Thanks Cor.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!