Jump to content
  • Advertisement

Archived

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

ThaUnknownProgga

OpenGL OpenGL multiple small rendering sections

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

I''ve recently started work on a 3d graphics editor of sorts. I was thinking of how I wanted to do it, and I decided I was sick of working soley with DirectX. It''s time I learn a thing or two about this OpenGL. First of all, OMG, this API is great! So easy! So functional! Alright anyway, here''s what I want to do. I want to have like 4 seperate little black boxes where rendering takes place (top view, side view...) right now, the whole window is black. I tried glViewport(100, 100, 100, 100); (much smaller than my window. This changes the size of the the triangle (all I''m drawing right now) but it still clears the whole screen to black. How can i make this only clear a small rectangular section that i specify? Also, how should i go about creating the 4 different rendering sections?

Share this post


Link to post
Share on other sites
Advertisement
Take a look at the glScissor() call, its what you need.

Nate
http://nate.scuzzy.net

Share this post


Link to post
Share on other sites
It''s still drawing the whole black. The call to
glClear(GL_COLOR_BUFFER_BIT / GL_DEPTH_BUFFER_BIT); is what''s making it all black obviously, but why doesn''t it just clear out what i have defined in my call to glScissor()? I did do glEnable(GL_SCISSOR_TEST);

Share this post


Link to post
Share on other sites
I just used this code as a test and it worked fine:

glScissor(0, 0, winW / 2, winH);
glClearColor(1, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT / GL_DEPTH_BUFFER_BIT);

glScissor(winW / 2, 0, winW / 2, winH);
glClearColor(1, 0, 1, 1);
glClear(GL_COLOR_BUFFER_BIT / GL_DEPTH_BUFFER_BIT);

Nate
http://nate.scuzzy.net

Share this post


Link to post
Share on other sites
Nate's right - I use similar code to draw four subwindows...


// Clear the whole window with current clearing color (this makes a background 'behind' the panes)
glClearColor ( 0.9, 0.9, 0.9, 1.0 );
glClear ( GL_COLOR_BUFFER_BIT / GL_DEPTH_BUFFER_BIT );

glEnable ( GL_SCISSOR_TEST );

/* Set and Draw the 4 viewports by using the sizes in the oglViewPorts array and the current scene */
for ( int ViewportIndex = 0; ViewportIndex < 4; ViewportIndex++ )
{
// Set viewport to our 'subwindows'
SizeViewport ( ViewportIndex );

// For rendering to subwindows only (so we don't clear the whole screen).
glScissor ((GLint)Pane[ViewportIndex].Left,
(GLint)Pane[ViewportIndex].Bottom,
(GLsizei)Pane[ViewportIndex].Width,
(GLsizei)Pane[ViewportIndex].Height);

DrawViewport ( ViewportIndex );
}

glDisable ( GL_SCISSOR_TEST ); // For rendering to 'subwindows'
glFlush ( );


The function SizeViewport ( .. ) is where I make the calls to glViewport, glOrtho that kind of thing. These aren't necessary every frame - only on a pane resize - I suppose I better change that

The function DrawViewport ( .. ) is where your 'usual' display funcion should go - in my program I render the same scene from a different point of view.

Using glScissor in this way is much easier than buggering about with multiple rendering contexts (IMO)

Paul Groves.
http://home.clara.net/paulyg
OpenGL for Beginners

Edited by - Pauly on 3/10/00 7:50:43 AM

Share this post


Link to post
Share on other sites
*Sigh* it''s still not working. I need to be able to just have this little square view in 3d, but it clears the whole window to black. Here is the code i use to initialize OpenGL:

int InitGL(GLvoid)
{
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glScissor(0, 0, 100, 100);
glEnable(GL_SCISSOR_TEST);
return TRUE;
}
then i this is my resize code which automatically gets called once. I pass 100 and 100 as the width and height.

GLvoid ReSizeGLScene(GLsizei width, GLsizei height)
{
if (height==0)
{
height=1;
}

glViewport(0, 0, width, height);
glScissor(0, 0, 100, 100);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
glEnable(GL_SCISSOR_TEST);
}

finally i do this to draw it:

int DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT / GL_DEPTH_BUFFER_BIT);
glEnable(GL_SCISSOR_TEST);
glScissor(0, 0, 100, 100);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-6.0f);
glRotatef(humor,1.0f,0.0f,0.0f);

glBegin(GL_TRIANGLES);
glColor3f(1.0, 0.0, 0.0);
glVertex3f( 0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glEnd();
glFlush();

humor+=0.2f;
return TRUE;
}

The problem is that it makes my entire window black, not just the rectangle (0, 0, 100, 100). I thought this was because of the call to glClear, but strangely enough it still makes all the window black even when i comment out glClear!!! Please help!

Share this post


Link to post
Share on other sites
Try disabling the scissor test - then glClear your screen using a different background colour (say white or grey). This will clear the whole screen.

Then enable the scissor test, change the background colour to black and call glClear again. Fingers crossed, you should see the difference.

Paul Groves.
http://home.clara.net/paulyg
OpenGL for Beginners

Share this post


Link to post
Share on other sites
Also, check to see if you are coloring the window black upon creation. (hbrBackground member of WNDCLASS)
I once thought I had this problem and had forgotten that I had specified BLACK_BRUSH there.


*oof*

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!