예제 #1
0
void CGLView::OnDraw(CDC* pDC)
{
	CDocument* pDoc = GetDocument();
	// TODO: 여기에 그리기 코드를 추가합니다.
	BeginGL();

	Setup_Viewport();

	ClearBuffer();

	Setup_Projection();

	Setup_Camera();

	glLightfv(GL_LIGHT0, GL_POSITION, m_vp.LightPosition0);

	DrawGL();


	glFinish();

	Capture();

	SwapBuffers(m_dp.hdc);

	EndGL();

}
예제 #2
0
HRESULT GLWindow::OnPaint(WPARAM wParam, LPARAM lParam)
{
    DrawGL();						// 绘制opengl场景
    SwapBuffers(m_hDc);				// 交换缓存
    ::ValidateRect(m_hWnd, NULL);   // 使窗口有效
    return TRUE;
}
Dlg_StructureEditor::Dlg_StructureEditor(CQDM_Edit* pEditIn, QWidget *parent)
	: QWidget(parent)
{
	pEdit = pEditIn;
	ui.setupUi(this);

	pGLWin = new CQOpenGL();
	ui.horizontalLayout->addWidget(pGLWin);
	resize(500, 300);
	SetupRef3DWindow();

////
//	connect(GLWindow, SIGNAL(FindDims(Vec3D*)), &MainObj, SLOT(GetDim(Vec3D*)));
//	connect(GLWindow, SIGNAL(DrawGL()), this, SLOT(DrawCurScene()));
//	connect(GLWindow, SIGNAL(MousePressIndex(int)), this, SLOT(SetGLSelected(int)));
//
//	//mouse handling
//	connect(GLWindow, SIGNAL(WantGLIndex(bool*)), this, SLOT(WantGLIndex(bool*)));
//	connect(GLWindow, SIGNAL(WantCoord3D(bool*)), this, SLOT(WantCoord3D(bool*)));
//
//	connect(GLWindow, SIGNAL(MouseMoveHover(float, float, float)), this, SLOT(HoverMove(float, float, float)));
//	connect(GLWindow, SIGNAL(LMouseMovePressed(float, float, float)), this, SLOT(LMouseDownMove(float, float, float)));
//	connect(GLWindow, SIGNAL(LMouseDown(float, float, float)), this, SLOT(LMouseDown(float, float, float)));
//	connect(GLWindow, SIGNAL(LMouseUp(float, float, float)), this, SLOT(LMouseUp(float, float, float)));
//	connect(GLWindow, SIGNAL(PressedEscape()), this, SLOT(PressedEscape()));
//	connect(GLWindow, SIGNAL(CtrlWheelRoll(bool)), this, SLOT(CtrlMouseRoll(bool)));
////

	connect(pGLWin, SIGNAL(FindDims(Vec3D*)), pEdit, SLOT(GetDim(Vec3D*)));
	connect(pGLWin, SIGNAL(DrawGL()), pEdit, SLOT(DrawSceneEdit()));

	connect(pGLWin, SIGNAL(WantGLIndex(bool*)), this, SLOT(WantGLIndex(bool*)));
	connect(pGLWin, SIGNAL(WantCoord3D(bool*)), this, SLOT(WantCoord3D(bool*)));
//	connect(pGLWin, SIGNAL(IsExtScene2D(bool*)), this, SLOT(IsEditMode(bool*)));

	connect(pGLWin, SIGNAL(MouseMoveHover(float, float, float)), this, SLOT(HoverMove(float, float, float)));
	connect(pGLWin, SIGNAL(LMouseMovePressed(float, float, float)), this, SLOT(LMouseDownMove(float, float, float)));
	connect(pGLWin, SIGNAL(LMouseDown(float, float, float)), this, SLOT(LMouseDown(float, float, float)));
	connect(pGLWin, SIGNAL(LMouseUp(float, float, float)), this, SLOT(LMouseUp(float, float, float)));
	connect(pGLWin, SIGNAL(PressedEscape()), this, SLOT(PressedEscape()));
	connect(pGLWin, SIGNAL(CtrlWheelRoll(bool)), this, SLOT(CtrlMouseRoll(bool)));

	connect(pEdit, SIGNAL(UpdateGLWindows()), this, SLOT(UpdateGLWins()));
	connect(pEdit, SIGNAL(GetCurMaterial(int*)), this, SLOT(CurMaterial(int*)));

	//connect this! void GetCurMaterial(int* MatIndex);
	
	//UI handlers:
	connect(ui.pencilButton, SIGNAL(clicked()), this, SLOT(ClickedPencil()));
	connect(ui.squareButton, SIGNAL(clicked()), this, SLOT(ClickedBox()));
	connect(ui.ellipseButton, SIGNAL(clicked()), this, SLOT(ClickedEllipse()));
	connect(ui.layerbackButton, SIGNAL(clicked()), this, SLOT(ClickedLayerBack()));
	connect(ui.layerforwardButton, SIGNAL(clicked()), this, SLOT(ClickedLayerForward()));
	connect(ui.refviewButton, SIGNAL(clicked(bool)), this, SLOT(ClickedRefView(bool)));

	IniUpdateUI();


}
예제 #4
0
void VoxCad::SetupRef3DWindow(void)
{
	Ref3DDockWidget = new QDockWidget(this);
	GLRef3DWin = new CQOpenGL();
	GLRef3DWin->SetViewCustom1();

	Ref3DDockWidget->setWidget(GLRef3DWin);
    Ref3DDockWidget->setWindowTitle("3D View");

	connect(Ref3DDockWidget->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(ViewRef3DWindow(bool)));
	connect(GLRef3DWin, SIGNAL(FindDims(Vec3D*)), &MainObj, SLOT(GetDim(Vec3D*)));
	connect(GLRef3DWin, SIGNAL(DrawGL()), &MainObj, SLOT(DrawSceneView()));

	Ref3DDockWidget->hide();
	Ref3DDockWidget->setFloating(true);
	Ref3DDockWidget->setGeometry (Ref3DDockWidget->parentWidget()->geometry().x()+10,Ref3DDockWidget->parentWidget()->geometry().y()+80,340,280 );

}
예제 #5
0
파일: QOpenGL.cpp 프로젝트: atsmsmr/VoxFab
int CQOpenGL::GLPickScene(int x, int y) //"draws" a section the scene in memory to see what we clicked on. returns name index
{
    makeCurrent(); //make sure we're using the right gl window information...
    GLuint selectBuf[BUFSIZE];
    GLint hits;

    GLint viewport[4];
    glGetIntegerv(GL_VIEWPORT, viewport); //gets current viewport info
    glSelectBuffer(BUFSIZE, selectBuf);
    glRenderMode(GL_SELECT);
    glInitNames();
    glPushName(-1);

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    /*  create 5x5 pixel picking region near cursor location      */
    gluPickMatrix ((GLdouble) x, (GLdouble) (viewport[3] - y), 1.0, 1.0, viewport);
    GLSetPersp();

    glMatrixMode(GL_MODELVIEW); //Back to model view
    glLoadIdentity();
    GLTranslateCam();
    emit DrawGL(FastMode); //Draw anything connected to this!

    glMatrixMode (GL_PROJECTION);
    glPopMatrix();
    glFlush();

    hits = glRenderMode (GL_RENDER);
    //processHits (hits, selectBuf);

    int CurClosest = -1;
    uint MinDist = UINT_MAX;
    for (int i = 0; i < hits; i++){
        if (selectBuf[4*i+1] < MinDist){
            MinDist = selectBuf[4*i+1];
            CurClosest = selectBuf[4*i+3];
        }
    }
    return CurClosest;
}
예제 #6
0
파일: OpenGLWindow.hpp 프로젝트: Tycheo/r3e
	int Run(){
		MSG msg;
		while(mRunning){
			if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
				if(msg.message == WM_QUIT){
					mRunning = FALSE;
				}else{
					TranslateMessage(&msg);
					DispatchMessage(&msg);
				}
			}else{
				if(!mActive) continue;
				DrawGL();
				SwapBuffers(mHDC);
			}
		}

		Destroy();

		return msg.wParam;
	}
예제 #7
0
void VoxCad::SetupGLWindow(void)
{
	GLWindow = new CQOpenGL();
	ui.horizontalLayout->addWidget(GLWindow);

	//opengl info
	connect(GLWindow, SIGNAL(FindDims(Vec3D*)), &MainObj, SLOT(GetDim(Vec3D*)));
	connect(GLWindow, SIGNAL(DrawGL()), this, SLOT(DrawCurScene()));
	connect(GLWindow, SIGNAL(MousePressIndex(int)), this, SLOT(SetGLSelected(int)));

	//mouse handling
	connect(GLWindow, SIGNAL(WantGLIndex(bool*)), this, SLOT(WantGLIndex(bool*)));
	connect(GLWindow, SIGNAL(WantCoord3D(bool*)), this, SLOT(WantCoord3D(bool*)));

	connect(GLWindow, SIGNAL(MouseMoveHover(float, float, float)), this, SLOT(HoverMove(float, float, float)));
	connect(GLWindow, SIGNAL(LMouseMovePressed(float, float, float)), this, SLOT(LMouseDownMove(float, float, float)));
	connect(GLWindow, SIGNAL(LMouseDown(float, float, float)), this, SLOT(LMouseDown(float, float, float)));
	connect(GLWindow, SIGNAL(LMouseUp(float, float, float)), this, SLOT(LMouseUp(float, float, float)));
	connect(GLWindow, SIGNAL(PressedEscape()), this, SLOT(PressedEscape()));
	connect(GLWindow, SIGNAL(CtrlWheelRoll(bool)), this, SLOT(CtrlMouseRoll(bool)));

}
void Dlg_StructureEditor::SetupRef3DWindow(void)
{
	RefWin = new QDialog(this);
	QHBoxLayout* HorLayout = new QHBoxLayout(RefWin);

	GLRef3DWin = new CQOpenGL();
	HorLayout->addWidget(GLRef3DWin);
	GLRef3DWin->SetViewCustom1();
	GLRef3DWin->setWindowTitle("3D View");

	connect(GLRef3DWin, SIGNAL(FindDims(Vec3D*)), pEdit, SLOT(GetDim(Vec3D*)));
	connect(GLRef3DWin, SIGNAL(DrawGL()), pEdit, SLOT(DrawSceneView()));

	QRect GLFrame = pGLWin->geometry();
	RefWin->setGeometry(GLFrame.x()+400, GLFrame.y()+50, 300, 200);

	//GLRef3DWin->
//	GLRef3DWin->hide();
//	GLRef3DWin->setFloating(true);
//	GLRef3DWin->setGeometry (Ref3DDockWidget->parentWidget()->geometry().x()+10,Ref3DDockWidget->parentWidget()->geometry().y()+80,340,280 );

}
예제 #9
0
void MolDisplayWin::CreateModeMovie(GWorldPtr lgWorld, Handle CompressedData,
									const qtData & myqtData) {
	float		offsetFactor;
	bool		savedrawmode=false;
	Rect		lDisplayRect = myqtData.DisplayRect;
	
	if (!MainData->cFrame->Vibs) return;
	Frame * lFrame = MainData->cFrame;
	if (MainData->GetDrawMode()) {
		savedrawmode = true;
		if (!Prefs->GetAnimateMode()) MainData->SetDrawMode(false);
	}
	long cmode = (lFrame->NumAtoms)*(lFrame->Vibs->CurrentMode);
	offsetFactor = 1.0/(4.5*Prefs->GetAnimationSpeed());
	float	VectorScale = Prefs->GetVectorScale();
	long AnimationSpeed = Prefs->GetAnimationSpeed();
	CPoint3D * ModeOffset = new CPoint3D[lFrame->NumAtoms];
	CPoint3D * SavedAtoms = new CPoint3D[lFrame->NumAtoms];
	if (!ModeOffset || !SavedAtoms) {
		return;	//insufficient memory
	}
	mpAtom * lAtoms = lFrame->Atoms;
	long iatm;
	for (iatm=0; iatm<(lFrame->NumAtoms); iatm++) {
		SavedAtoms[iatm] = lAtoms[iatm].Position;
		ModeOffset[iatm] = lFrame->Vibs->NormMode[iatm+cmode];
		ModeOffset[iatm] *= VectorScale;
	}
	MainData->ResetRotation();
	ReleaseLists();
	DrawGL();

	OSErr	myErr;
	long npoint = 0;
	long inc = 1;
	ProgressInd->SetScaleFactor(100.0/((float) 4*AnimationSpeed));
	for (long i=0; i<4*AnimationSpeed; i++) {
		ProgressInd->UpdateProgress(i);
		if ((npoint==AnimationSpeed)||(npoint==-AnimationSpeed)) {
			inc *= -1;
			offsetFactor *= -1.0;
		}
		npoint += inc;

		//	create a pict of the current molecule display
		wxImage mImage = glCanvas->getImage(0,0);
		wxBitmap * mBitmap = new wxBitmap(mImage);
		//The following utilizes a Mac specific internal pair of calls
		//to get a PicHandle from a wxBitmap.
		wxBitmapRefData * mBitmapData = mBitmap->GetBitmapData();
		PicHandle tempPict = mBitmapData->GetPictHandle();
		
		CGrafPtr	lSavedPort;
		GDHandle	lSavedGDH;
		long		dataSize;
		unsigned char similarity;
		
		if (tempPict) {	//Got a PICT, draw it into the GWorld
			HLock(CompressedData);
			Ptr compressedDataPtr = *CompressedData;

			GetGWorld (&lSavedPort, &lSavedGDH);
			SetGWorld (lgWorld, NULL);
			
			EraseRect(&lDisplayRect);
			DrawPicture(tempPict, &(lDisplayRect));

			delete mBitmap;
			
			SetGWorld (lSavedPort, lSavedGDH);
			
			PixMapHandle myPixMap = GetPortPixMap(lgWorld);
			myErr = CompressSequenceFrame(myqtData.seqID, myPixMap, &lDisplayRect,
										  codecFlagUpdatePreviousComp, compressedDataPtr, &dataSize, &similarity, NULL);
			
			TimeValue test;//I don't use this value, but Carbon requires it
			myErr = AddMediaSample(myqtData.theMedia, CompressedData, 0,    /* no offset in data */
					dataSize, 1,
					(SampleDescriptionHandle)myqtData.imageDesc, 1,    /* one sample */
					0,    /* self-contained samples */
					&test);
		}
		for (iatm=0; iatm<(lFrame->NumAtoms); iatm++) {
			lAtoms[iatm].Position.x += offsetFactor*(ModeOffset[iatm].x);
			lAtoms[iatm].Position.y += offsetFactor*(ModeOffset[iatm].y);
			lAtoms[iatm].Position.z += offsetFactor*(ModeOffset[iatm].z);
		}

		MainData->ResetRotation();
		ReleaseLists();
		DrawGL();
	}
	for (iatm=0; iatm<(lFrame->NumAtoms); iatm++) {
		lAtoms[iatm].Position = SavedAtoms[iatm];	
	}
	MainData->ResetRotation();

	if (ModeOffset) delete [] ModeOffset;
	if (SavedAtoms) delete [] SavedAtoms;
	MainData->SetDrawMode(savedrawmode);
	ReleaseLists();
	DrawGL();
}
예제 #10
0
void MolDisplayWin::CreateFrameMovie(GWorldPtr lgWorld, Handle CompressedData,
									 const qtData & myqtData, bool IncludeEPlot) {
	OSErr	myErr;
	long AnimateTime = Prefs->GetAnimateTime();
	if (AnimateTime <= 0) AnimateTime = 1;
	long SavedFrameNum = MainData->GetCurrentFrame();
	Rect	lDisplayRect = myqtData.DisplayRect;
	Rect	EPlotRect;
	EPlotRect = myqtData.DisplayRect;
	EPlotRect.left = EPlotRect.right;
	EPlotRect.right = myqtData.FullRect.right;
	ProgressInd->SetScaleFactor(100.0/((float) MainData->NumFrames));

	for (long i=1; i<=MainData->NumFrames; i++) {
		ProgressInd->UpdateProgress(i);
		MainData->SetCurrentFrame(i);
		//Check for and update any surfaces depending on the screen plane
		Surface * temp = MainData->cFrame->SurfaceList;
		while (temp) {
			temp->RotateEvent(MainData);
			temp = temp->GetNextSurface();
		}
		MainData->ResetRotation();
		ReleaseLists();
		DrawGL();

		//	create a pict of the current molecule display
		wxImage mImage = glCanvas->getImage(0,0);
		wxBitmap * mBitmap = new wxBitmap(mImage);
		//The following utilizes a Mac specific internal pair of calls
		//to get a PicHandle from a wxBitmap.
		wxBitmapRefData * mBitmapData = mBitmap->GetBitmapData();
		PicHandle tempPict = mBitmapData->GetPictHandle();

		CGrafPtr	lSavedPort;
		GDHandle	lSavedGDH;
		long		dataSize;
		unsigned char similarity;
		
		if (tempPict) {	//Got a PICT, draw it into the GWorld
			HLock(CompressedData);
			Ptr compressedDataPtr = *CompressedData;
			GetGWorld (&lSavedPort, &lSavedGDH);
			SetGWorld (lgWorld, NULL);
			
			EraseRect(&lDisplayRect);
			DrawPicture(tempPict, &(lDisplayRect));
			
			delete mBitmap;
			
			if (IncludeEPlot) {
				energyPlotWindow->FrameChanged();
				wxBitmap * ePlotBitMap = NULL;
				energyPlotWindow->CopyToBitMap(&ePlotBitMap);
				if (ePlotBitMap) {
					wxBitmapRefData * mBitmapData = mBitmap->GetBitmapData();
					PicHandle tempPict = mBitmapData->GetPictHandle();
					if (tempPict) {
						SetGWorld (lgWorld, NULL);
						
						EraseRect(&EPlotRect);
						DrawPicture(tempPict, &(EPlotRect));
					}
					delete ePlotBitMap;
				}
			}
			
			SetGWorld (lSavedPort, lSavedGDH);
			
			PixMapHandle myPixMap = GetPortPixMap(lgWorld);
			myErr = CompressSequenceFrame(myqtData.seqID, myPixMap, &(myqtData.FullRect),
										  codecFlagUpdatePreviousComp, compressedDataPtr, &dataSize, &similarity, NULL);
			
			TimeValue test;//I don't use this value, but Carbon requires it
			myErr = AddMediaSample(myqtData.theMedia, CompressedData, 0,    /* no offset in data */
				dataSize, AnimateTime,
				(SampleDescriptionHandle)myqtData.imageDesc, 1,    /* one sample */
				0,    /* self-contained samples */
				&test);
		}
	}
	MainData->SetCurrentFrame(SavedFrameNum);
	MainData->ResetRotation();
	ReleaseLists();
	DrawGL();
}
예제 #11
0
int main(int argc, char *argv[])
{
    SDL_Event event;
    const Uint32 time_per_frame = 1000/FPS;
    unsigned int width = LARGEUR_FENETRE;
    unsigned int height = HAUTEUR_FENETRE;

    Uint32 last_time,current_time,elapsed_time; //for time animation
    Uint32 start_time,stop_time; //for frame limit

    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
    atexit(stop);
    /* playsound("alig.mp3"); --------------------------------- MUSIC */
    SDL_WM_SetCaption("Brutal Gore", NULL);
    SDL_SetVideoMode(width, height, 32, SDL_OPENGL);
    //initFullScreen(&width,&height);

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity( );
    gluPerspective(70,(double)width/height,0.001,1000);

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_TEXTURE_2D);

    chargerTextures();

    camera = new FreeFlyCamera(Vector3D(0,0,2));

    last_time = SDL_GetTicks();
    for (;;)
    {

        start_time = SDL_GetTicks();

        while(SDL_PollEvent(&event))
        {
            switch(event.type)
            {
                case SDL_QUIT:
                exit(0);
                break;
                case SDL_KEYDOWN:
                switch (event.key.keysym.sym)
                {
                    case SDLK_p:
                    takeScreenshot("test.bmp");
                    break;
                    case SDLK_ESCAPE:
                    exit(0);
                    break;
                    default :
                    camera->OnKeyboard(event.key);
                }
                break;
                case SDL_KEYUP:
                camera->OnKeyboard(event.key);
                break;
                case SDL_MOUSEMOTION:
                camera->OnMouseMotion(event.motion);
                break;
                case SDL_MOUSEBUTTONUP:
                case SDL_MOUSEBUTTONDOWN:
                camera->OnMouseButton(event.button);
                break;
            }
        }

        current_time = SDL_GetTicks();
        elapsed_time = current_time - last_time;
        last_time = current_time;

        camera->animate(elapsed_time);

        DrawGL();

        stop_time = SDL_GetTicks();
        if ((stop_time - last_time) < time_per_frame)
        {
            SDL_Delay(time_per_frame - (stop_time - last_time));
        }

    }

    return 0;
}
예제 #12
0
파일: QOpenGL.cpp 프로젝트: atsmsmr/VoxFab
void CQOpenGL::GLDrawScene()
{
    CGL_Utils::CurContextID = MyID;
    glRenderMode(GL_RENDER);

    glMatrixMode(GL_PROJECTION); // Select the Projection Matrix
    glLoadIdentity();
    GLSetPersp(); //dynamic control over the perspective

    //move the view to follow something if this signal is hooked up to something that changes its value
    Vec3D<> CurTarget(m_Cam.TargetX, m_Cam.TargetY, m_Cam.TargetZ);
    emit FindCamTarget(&CurTarget);
    m_Cam.TargetX = CurTarget.x;
    m_Cam.TargetY = CurTarget.y;
    m_Cam.TargetZ = CurTarget.z;

    // Set camera view
    glMatrixMode(GL_MODELVIEW); //Back to model view
    glLoadIdentity();
    GLTranslateCam();

    GLSetLighting(); //Enable to have specular highlight in accurate place
    //End Bonuses


    glPushMatrix();
    switch (CurView){ //this makes sure the axes and bounds are out front of drawing...
    case VTOP: glTranslated(0, 0, CurEnv.z); break;
    case VBOTTOM: glTranslated(0, 0, -CurEnv.z); break;
    case VLEFT: glTranslated(0, -CurEnv.y, 0); break;
    case VRIGHT: glTranslated(0, CurEnv.y, 0); break;
    case VFRONT: glTranslated(CurEnv.x, 0, 0); break;
    case VBACK: glTranslated( -CurEnv.x, 0, 0); break;
    }

    if (bDrawAxes)
        GLDrawAxes();

    glPopMatrix();

    if (bDrawBounds)
        GLDrawBounds();

//	CGL_Utils::DrawSphere(LastPickedPoint, 0.0002, Vec3D<>(1,1,1), CColor(.5, .5, .5));

    QTime t;
    t.start();
    //draw geometry:
    emit DrawGL(FastMode); //Draw anything connected to this!

    int MStoDraw = t.elapsed();
    if (MStoDraw > 200 && !IsFastMode() && !AskedAboutFastMode){
        AskedAboutFastMode = true;
        if (QMessageBox::question(NULL, "Enter fast draw mode?", "Do you want to enter fast drawing mode?", QMessageBox::Yes | QMessageBox::No)==QMessageBox::Yes)
            EnterFastMode(true);
    }

//	glPushMatrix();
    //draw 2D overlay!


    glPushAttrib(GL_TRANSFORM_BIT | GL_VIEWPORT_BIT);
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
      glLoadIdentity();
      glOrtho(0, WindowSize.width(), WindowSize.height(), 0, -1, 1);
      glMatrixMode(GL_MODELVIEW);
      glPushMatrix();
        glLoadIdentity();
        glDisable(GL_LIGHTING);
        emit DrawGLOverlay(); //draw any 2D connected to this!
      glPopMatrix();
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glPopAttrib();

}
예제 #13
0
void ViewportWidget::paintGL()
{
	DrawGL();
}