PDA

View Full Version : problem determining the opengl drawing area



markitus
04-21-2005, 09:31 AM
hello everybody.
I'm trying to create a program using Visual C++ and Opengl. I've already completed all the steps for the settings, so my project is able to have opengl code.
Well, i have a normal MFC application with menu and toolbar and stuff, and my intention is to use Opengl in the view window, but just in a determined area (a rectangle).

void CMy3DspineView::OnDraw(CDC* pDC)
{

CMy3DspineDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here


// Tell windows that its OpenGL time
wglMakeCurrent(pDC->m_hDC, m_hRC);

// create an instance of the CRect object
CRect rect;

//Get the client area
GetClientRect(&rect);


///////////////////////////////////////////////////////////////////////////
// Let's Paint the Background //
///////////////////////////////////////////////////////////////////////////

// Set brush to desired background color

CBrush backBrush(RGB(162,162,162));

// Save old brush
CBrush* pOldBrush = pDC->SelectObject(&backBrush);



// Fill the Client Area Using our new Brush
pDC->FillRect(&rect, &backBrush);


//Creates rectangle for visualization
CRect vis_rect;

vis_rect.left=rect.left+20;
vis_rect.right=2*(rect.right/3) -20;
vis_rect.top=rect.top+20;
vis_rect.bottom=rect.bottom-20;

CPen vis_rectPen(PS_SOLID,3,RGB(0,0,0));
CPen* pOldPen = pDC->SelectObject(&vis_rectPen);

pDC->Rectangle(&vis_rect);



//CBrush vis_rectBrush(RGB(255,255,255));
CBrush vis_rectBrush(RGB(0,0,0));

pDC->FillRect(&vis_rect,&vis_rectBrush);

//Creates rectangles for control and additional information
CRect rect3D;
CRect movie_rect;
CRect patient_rect;
CRect process_rect;


movie_rect.left=2*(rect.right/3) +20;
movie_rect.right=rect.right-20;
movie_rect.top=rect.top+20;
movie_rect.bottom=rect.bottom/4;

CPen rect3DPen(PS_DOT,0.7,RGB(0,0,0));
pOldPen = pDC->SelectObject(&rect3DPen);

pDC->Rectangle(&movie_rect);
pDC->DrawText("Movie controls", &movie_rect , DT_SINGLELINE | DT_CENTER | DT_VCENTER);


rect3D.left=2*(rect.right/3) +20;
rect3D.right=rect.right-20;
rect3D.top=movie_rect.bottom+20;
rect3D.bottom=2*(rect.bottom/3);

pDC->Rectangle(&rect3D);
pDC->DrawText("3D controls", &rect3D , DT_SINGLELINE | DT_CENTER | DT_VCENTER);


patient_rect.left=2*(rect.right/3) +20;
patient_rect.right=rect.right-20;
patient_rect.top=rect3D.bottom+20;
patient_rect.bottom=rect.bottom-60;

pDC->Rectangle(&patient_rect);
pDC->DrawText("Patient Information", &patient_rect , DT_SINGLELINE | DT_CENTER | DT_VCENTER);

process_rect.left=2*(rect.right/3) +20;
process_rect.right=rect.right-20;
process_rect.top=patient_rect.bottom+20;
process_rect.bottom=process_rect.top+20;

pDC->Rectangle(&process_rect);
pDC->DrawText("Process transitions...", &process_rect , DT_SINGLELINE | DT_CENTER | DT_VCENTER);


}
for now i've just prepared how will look the interface. what i want is to use OPENGL instructions to draw into the black rectangle (vis_rect). how could i do that?? for instance , for starting i would like to draw a simple triangle on it, using this code...

glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(2.0f, 0.0f, 0.0f);
glVertex3f(1.0f, 1.0f, 0.0f);
glEnd();but how could i specify that i want to use OPENGL only there?? here u can find a screenshot of my program, how it looks like right now.
http://www.codeguru.com/forum/showthread.php?t=338010

T101
04-21-2005, 11:16 PM
From the Bluebook:


void glViewport( GLint x, GLint y, GLsizei width, GLsizei height )

PARAMETERS
x, y Specify the lower left corner of the viewport rectangle, in pixels. The default is (0,0).

width, height Specify the width and height, respectively, of the viewport. When a GL context is first attached to a window, width and height are set to the dimensions of that window.

The only complication for you is that you'll have to reverse the y-coordinates because opengl coordinates are from bottom to top instead of top to bottom like window coordinates. Make a simple sketch and you'll know how to set the y coordinates.