[comp.sys.sgi] drawing in subwindows

margaret@cs.utah.edu (Malgorzata Sturgill) (08/14/90)

Hi,
	I am trying to draw in subwindows ( open with swinopen ). I finally 
managed to persuade my code to draw, but unfortunately it does not draw where 
I expect. I have included a piece of code to ilustrate. All this program does 
it opens a 300x300 parent window (black) and then opens a white 200x200 white 
subwindow. the program is then supposed to draw the diagonals of the subwindow 
in red. Well it does not. It does draw a cross, but it does not fill the whole
window. Am I just doing something stupid?

					Any help would be great,

							m.
------------------ Code Follows ---------------------------------------------

#include <stdio.h>
#include <gl.h>
#include <device.h>

long parent, child;

main(argc, argv)
int argc;
char *argv[];
{
short data;

	foreground();
	prefposition(500,800,500,800);
	parent = winopen("parent") ;
	gconfig();
	reshapeviewport();
	color(BLACK);
	clear();
	child = swinopen(parent);
	winposition(50,250,50,250);
	gconfig();
	color(WHITE);
	clear();
	qenter(REDRAW,(short)child);

	while (TRUE){
		while (qtest()){
			switch(qread(&data)){
				case REDRAW:
					if ((long)data == parent){
						winset(parent);
						reshapeviewport();
						color(BLACK);
						clear();
						break;
					}
					if ((long)data == child){
						redr();
						printf("child redrawn\n");
					}
					break;
				default:
					break;

			}
		}
	}
}

redr(){
	winset(child);
	reshapeviewport();
	color(WHITE);
	clear();
	color(RED);
	move2(0,0);
	draw2(199,199);
	move2(0,199);
	draw2(199,0);
}

Malgorzata Marek Sturgill		margaret@cs.utah.edu
					margaret@ms.uky.edu

"A sphere isn't that simple when you get into higher dimensions
 - it's a bit non-flat."

			- Annonymous
Malgorzata Marek Sturgill		margaret@cs.utah.edu
					margaret@ms.uky.edu

"A sphere isn't that simple when you get into higher dimensions

bennett@sgi.com (Jim Bennett) (08/15/90)

margaret@cs.utah.edu (Malgorzata Sturgill) writes:

> Hi,
> 	I am trying to draw in subwindows ( open with swinopen ). I finally 
> managed to persuade my code to draw, but unfortunately it does not draw where 
> I expect. I have included a piece of code to ilustrate.
>
>			...

You just need to set the projection, for example:

	ortho2 (-0.5, 199.5, -0.5, 199.5);

after the call to reshapeviewport() in your redraw routine.  Then
it works like you would expect.

Jim

thant@horus.esd.sgi.com (Thant Tessman) (08/16/90)

In article <1990Aug14.100020.5096@hellgate.utah.edu>,
margaret@cs.utah.edu (Malgorzata Sturgill) writes:
> 
> Hi,
> 	I am trying to draw in subwindows ( open with swinopen ). I finally 
> managed to persuade my code to draw, but unfortunately it does not
draw where 
> I expect. I have included a piece of code to ilustrate. All this
program does 
> it opens a 300x300 parent window (black) and then opens a white
200x200 white 
> subwindow. the program is then supposed to draw the diagonals of the
subwindow 
> in red. Well it does not. It does draw a cross, but it does not fill
the whole
> window. Am I just doing something stupid?
> #include <device.h>

I'm not sure what the default behavior of subwindows is supposed to be,
but you could just add an ortho2 to your redr to get what you want:

 
 redr(){
 	winset(child);
 	reshapeviewport();

	ortho2(0.0, 200.0, 0.0, 200.0);		/* like this */

 	color(WHITE);
 	clear();
 	color(RED);
 	move2(0,0);
 	draw2(199,199);
 	move2(0,199);
 	draw2(199,0);
 }

 
> Malgorzata Marek Sturgill		margaret@cs.utah.edu
> 					margaret@ms.uky.edu
> 

thant