Jump to content
  • Advertisement
Sign in to follow this  
Stormtrooper

glScissor [ FIXED]

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

EDIT: I fixed the problem. I wasn't calculation the glScissor rect correctly. Thanks for the help! Ok, I'm trying to scissor the current widget of my gui when I draw them. The way I have it setup is I have a top container, then have another container as a sub window, with a widget inside the window. top->draw(),drawChildren()-> window->draw(),drawChildren()-> button->draw() If I only scissor just before I loop through the widgets, the top and window renders. If I scissor in the loop through the widgets and before I loop through the widgets, only top draws. If I scissor only for each widget in the loop, only the top draws. I have no idea how to fix it. I have two functions for widgets(containers are based off of widgets): getSize() getRelativeSize() these get the x/y/width/height values. Relative gets the relative location from the parent widget.

void VideoDriver::pushClip( Rect &rect )
{
	//mClipStack.push( rect );
	
	glScissor( rect.x, rect.y, rect.width, rect.height);
}

void VideoDriver::popClip()
{
	/*mClipStack.pop();

	if(	mClipStack.empty() )
		return;*/

	glScissor( 0, 0, mWidth, mHeight);
}

void Container::drawChildren( VideoDriver *video )
{
	std::list<Widget*>::iterator itr;
	video->pushClip( mSize );
	for(itr = mWidgetList.begin(); itr != mWidgetList.end(); ++itr )
	{
		if( (*itr)->getEnabled() == true && (*itr)->getVisible() == true )
		{
			//video->pushClip( (*itr)->getSize() );
			(*itr)->draw( video );
			//video->popClip();
			
		}
	}
	video->popClip();
}

Rect Widget::getRelativeSize()
{
	Rect size;

	if( getParent() != NULL )
	{
		
		size.x = mSize.x + getParent()->getSize().x;
		size.y = mSize.y + getParent()->getSize().y;
		size.width = mSize.width;
		size.height = mSize.height;
		return size;
	}

	return mSize;
}


[Edited by - Stormtrooper on July 8, 2007 11:54:49 PM]

Share this post


Link to post
Share on other sites
Advertisement
Here is the gui draw code, if you need it


void Gui::draw()
{
mVideoDriver->beginRendering();
if( mTop != NULL )
{
Rect size;
size.x = 0;
size.y = 0;
size.width = mVideoDriver->getWidth();
size.height = mVideoDriver->getHeight();

mVideoDriver->pushClip( size );
mTop->draw( mVideoDriver );
mVideoDriver->popClip();
}
mVideoDriver->endRendering();
}

Share this post


Link to post
Share on other sites
I am not sure I understood the entire gist of you question(screenshots?) but here are some ideals to mitigate problems you may or may not have.

0) Make sure glScissor() gets the absolute screen position of the widget and not the relative position.

1) Here's a way to adjust the scissor area when going through widgets
The method assumes children should be contained at least partially within the parent region. Before setting the scissor rect, clip the widget's rect with the previous rect in clip stack. This ensure the children is clipped to the parent.

//This is verbose pseudo code
PushClip(Rect r)
{
if(stack.empty()){
stack.push(r);
glEnable(GL_SCISSOR_TEST);
}else{
//clip r with previous rect push on the stack
if(!ClipRect2Rect(r,stack.peek()){
//r has been fully clip (Entirely outside the previous clipping rect)
stack.push(stack.peek()); //just use the previous clipping rect?
}else{
stack.push(r);//r contain the newly clipped rect(it will be partially or entirely inside the previous clipping rect)
}
}
glScissor(r.x,r.y,r.h,r.w)
}
PopClip()
{
stack.pop()
if(!stack.empty()){
Rect r= stack.peek()
//restore previous clip rect
glScissor(r.x,r.y,r.w,r.h)
}else
glDisable(GL_SCISSOR_TEST)
}





2) Check to make sure the coordinates to glScissor are correct. In the case where the viewpoint is setup so that the origin is in the upper-left of the screen, glScissor will still assume the origin is in the lower-left corner of the screen. So in that case you would need to perform transformation on the coordinates before passing them to glScissor.

Share this post


Link to post
Share on other sites
Ok, thanks for your help I'll try it out.

My problem is that its not drawing a button that is within the window container. It might be because that area is already clipped and does not need to be re-clipped? The reason why I clip the containers is so if a widget goes out of the parent, it won't get drawn. I wonder if I shouldn't clip the actual widget.

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!