Showing posts with label OpenGL. Show all posts
Showing posts with label OpenGL. Show all posts
2016/10/05
Using VTK with MFC Project
VTK 버전 7.0이 나와서 새로 빌드도 해 보고 다시 공부좀 해볼까 하여 오랜만에 VTK를 빌드해 보았다.
아주 오랜만에 다시 해 보는 것이고 이전 기록이 많지않아 동일한 시행착오를 피할 수 없었다.
빌드를 무사히 마치고 Visual Studio 에서 테스트 하는데 더 큰 걸림돌이 있었다.
검색 결과 CMake를 이용하지 않는 경우 초기화(?) 코드가 필요 하였다.
게다가 버전 7은 버전 6에서 변경된 사항이 있어 동일한 코드로 초기화가 되지 않았다.
추후 동일한 문제로 고생하지 않기 위해 기록을 남긴다.
For VTK 6.x
다른 헤더파일을 포함하기 전에 먼저 "vtkAutoInit.h"를 포함하고 일부 모듈을 초기화 해 주어야 한다.
For VTK 7.x
VTK 7.x의 경우 OpenGL이 OpenGL2로 새롭게 바뀌었으며 빌드할 때 별도의 설정을 하지 않은 경우 OpenGL2로 설정이 되기때문에 VTK 6.x 에서 초기에 수행한 OpenGL 설정을 OpenGL2 로 변경을 해 주어야 한다. 그리고 vtkRenderingFreeTypeOpenGL 은 삭제되었다 한다.
아주 오랜만에 다시 해 보는 것이고 이전 기록이 많지않아 동일한 시행착오를 피할 수 없었다.
빌드를 무사히 마치고 Visual Studio 에서 테스트 하는데 더 큰 걸림돌이 있었다.
검색 결과 CMake를 이용하지 않는 경우 초기화(?) 코드가 필요 하였다.
게다가 버전 7은 버전 6에서 변경된 사항이 있어 동일한 코드로 초기화가 되지 않았다.
추후 동일한 문제로 고생하지 않기 위해 기록을 남긴다.
For VTK 6.x
다른 헤더파일을 포함하기 전에 먼저 "vtkAutoInit.h"를 포함하고 일부 모듈을 초기화 해 주어야 한다.
#include "vtkAutoInit.h" VTK_MODULE_INIT(vtkInteractionStyle); VTK_MODULE_INIT(vtkRenderingFreeType); VTK_MODULE_INIT(vtkRenderingFreeTypeOpenGL); VTK_MODULE_INIT(vtkRenderingOpenGL); #define vtkRenderingCore_AUTOINIT 4(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingFreeTypeOpenGL,vtkRenderingOpenGL) #define vtkRenderingVolume_AUTOINIT 1(vtkRenderingVolumeOpenGL)http://www.vtk.org/Wiki/VTK/VTK_6_Migration/Factories_now_require_defines
For VTK 7.x
VTK 7.x의 경우 OpenGL이 OpenGL2로 새롭게 바뀌었으며 빌드할 때 별도의 설정을 하지 않은 경우 OpenGL2로 설정이 되기때문에 VTK 6.x 에서 초기에 수행한 OpenGL 설정을 OpenGL2 로 변경을 해 주어야 한다. 그리고 vtkRenderingFreeTypeOpenGL 은 삭제되었다 한다.
#include "vtkAutoInit.h" VTK_MODULE_INIT(vtkInteractionStyle); VTK_MODULE_INIT(vtkRenderingFreeType); VTK_MODULE_INIT(vtkRenderingOpenGL2); #define vtkRenderingCore_AUTOINIT 3(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingOpenGL2)http://www.visitusers.org/index.php?title=VTK_7.1_Upgrade
Labels:
C++
,
cmake
,
MFC
,
OpenGL
,
OpenGL2
,
VTK
,
VTK_MODULE_INIT
,
vtkAutoInit
2009/03/23
OpenGL 로 간단하게 2D Drawing 하는 기본 소스
OpenGL 로 간단하게 2D 드로잉 하는 걸 공부하고 있는데 진도가 느리다.
아래 소스는 Visual C++ 에서 OpenGL을 이용하여 간단하게 2D 드로잉을 하는 기본 소스이다.

glut를 사용하지 않고 기본으로 포함되어있는 OpenGL 만을 이용한 소스이다. 분석을 하여 나중에는 glut까지 이용하는 코드를 작성해 보아야겠다.
Original Post : http://neodreamer-dev.tistory.com/274
아래 소스는 Visual C++ 에서 OpenGL을 이용하여 간단하게 2D 드로잉을 하는 기본 소스이다.
// stdafx.h
////////////////////////////////////////////////////////////////////////////////
// for OpenGL
#pragma comment (lib, "opengl32.lib")
#pragma comment (lib, "glu32.lib")
#pragma comment (lib, "glaux.lib")
#include <gl/GL.h>
#include <gl/GLU.h>
#include <gl/GLAux.h>
// for OpenGL
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Header
HGLRC m_hRC; //Rendering Context
CDC* m_pDC; //Device Context
int m_nPixelFormat;
BOOL InitializeOpenGL();
void RenderScene();
////////////////////////////////////////////////////////////////////////////////
// Source
int CGLTestView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
InitializeOpenGL();
return 0;
}
BOOL CGLTestView::InitializeOpenGL()
{
//Get a DC for the Client Area
m_pDC = new CClientDC(this);
//Failure to Get DC
if(m_pDC == NULL)
{
MessageBox( _T("Error Obtaining DC") );
return FALSE;
}
////////////////////////////////////////////////////////////////////////////////
// Setup Pixel Format
static PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
32, // color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accumulation bits ignored
32, // z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};
int m_nPixelFormat = ::ChoosePixelFormat( m_pDC->GetSafeHdc(), &pfd );
if ( m_nPixelFormat == 0 )
{
return FALSE;
}
if ( ::SetPixelFormat( m_pDC->GetSafeHdc(), m_nPixelFormat, &pfd ) == FALSE )
{
return FALSE;
}
////////////////////////////////////////////////////////////////////////////////
//Create Rendering Context
m_hRC = ::wglCreateContext( m_pDC->GetSafeHdc() );
//Failure to Create Rendering Context
if( m_hRC == 0 )
{
MessageBox( _T("Error Creating RC") );
return FALSE;
}
//Make the RC Current
if( ::wglMakeCurrent ( m_pDC->GetSafeHdc (), m_hRC ) == FALSE )
{
MessageBox( _T("Error making RC Current") );
return FALSE;
}
//Specify Black as the clear color
::glClearColor( 0.0f, 0.0f, 0.0f, 0.0f);
//Specify the back of the buffer as clear depth
//::glClearDepth( 1.0f );
//Enable Depth Testing
//::glEnable( GL_DEPTH_TEST );
::glDisable( GL_DEPTH_TEST ); // For 2D
return TRUE;
}
void CGLTestView::OnDraw(CDC* /*pDC*/)
{
CGLTestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// 컬러버퍼와 깊이버퍼를 초기화
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
RenderScene();
// Tell OpenGL to flush its pipeline
::glFinish();
// Now Swap the buffers
::SwapBuffers( m_pDC->GetSafeHdc() );
}
void CGLTestView::RenderScene()
{
glBegin(GL_TRIANGLES);
{
glVertex2f( 0.0f, 0.0f );
glVertex2f( 20.0f, 0.0f );
glVertex2f( 0.0f, 20.0f );
}
glEnd();
}
void CGLTestView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
GLdouble aspect_ratio; // width/height ratio
if ( 0 >= cx || 0 >= cy )
{
return;
}
// select the full client area
::glViewport(0, 0, cx, cy);
// compute the aspect ratio
// this will keep all dimension scales equal
aspect_ratio = (GLdouble)cx/(GLdouble)cy;
// select the projection matrix and clear it
::glMatrixMode(GL_PROJECTION);
::glLoadIdentity();
// select the viewing volume
//::gluPerspective(45.0f, aspect_ratio, .01f, 200.0f);
GLfloat nRange = 50.0f;
if (cx <= cy)
{
glOrtho(-nRange, nRange, -nRange * cy / cx,
nRange * cy / cx, -nRange, nRange );
}
else
{
glOrtho(-nRange * cx / cy,
nRange * cx / cy,
-nRange, nRange, -nRange, nRange);
}
// switch back to the modelview matrix and clear it
::glMatrixMode(GL_MODELVIEW);
::glLoadIdentity();
}
결과 화면
glut를 사용하지 않고 기본으로 포함되어있는 OpenGL 만을 이용한 소스이다. 분석을 하여 나중에는 glut까지 이용하는 코드를 작성해 보아야겠다.
Original Post : http://neodreamer-dev.tistory.com/274
2009/03/12
C++ Builder 에서 OpenGL을 사용하기 위한 기본 뼈대
원문 주소 : http://edn.embarcadero.com/article/10528
C++ Builder 의 TForm 위에 OpenGL을 드로잉하기 위한 기본적인 뼈대 이다. C++ Builder 에서 OpenGL을 사용하기 위한 방법을 찾다가 발견한 정보이다.
Original Post : http://neodreamer-dev.tistory.com/269
C++ Builder 의 TForm 위에 OpenGL을 드로잉하기 위한 기본적인 뼈대 이다. C++ Builder 에서 OpenGL을 사용하기 위한 방법을 찾다가 발견한 정보이다.
/////////////////////////////////////////////////////////////////////////////
//glskeleton.h
/////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
#include <vcl/vcl.h>
//---------------------------------------------------------------------------
#ifndef GLSkeletonH
#define GLSkeletonH
//---------------------------------------------------------------------------
#include <vcl/Classes.hpp>
#include <vcl/Controls.hpp>
#include <vcl/StdCtrls.hpp>
#include <vcl/Forms.hpp>
#include <gl/gl.h>
#include <gl/glu.h>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
published: // IDE-managed Components
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormDestroy(TObject *Sender);
void __fastcall FormResize(TObject *Sender);
void __fastcall FormPaint(TObject *Sender);
private: // User declarations
HDC hdc;
HGLRC hrc;
int PixelFormat;
public: // User declarations
fastcall TForm1(TComponent* Owner);
void __fastcall IdleLoop(TObject*, bool&);
void __fastcall RenderGLScene();
void __fastcall SetPixelFormatDescriptor();
};
/////////////////////////////////////////////////////////////////////////////
// glskeleton.cpp
/////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
extern TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
#include <vcl/vcl.h>
#pragma hdrstop
#include "GLSkeleton.h"
//---------------------------------------------------------------------------
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Application->OnIdle = IdleLoop;
_control87(MCW_EM, MCW_EM);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::IdleLoop(TObject*, bool& done)
{
done = false;
RenderGLScene();
SwapBuffers(hdc);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RenderGLScene()
{
//Place your OpenGL drawing code here
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
hdc = GetDC(Handle);
SetPixelFormatDescriptor();
hrc = wglCreateContext(hdc);
wglMakeCurrent(hdc, hrc);
SetupRC();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SetupRC()
{
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
ReleaseDC(hdc);
wglMakeCurrent(hdc, NULL);
wglDeleteContext(hrc);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SetPixelFormatDescriptor()
{
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
24,
0,0,0,0,0,0,
0,0,
0,0,0,0,0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,0
};
PixelFormat = ChoosePixelFormat(hdc, &pfd);
SetPixelFormat(hdc, PixelFormat, &pfd);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormResize(TObject *Sender)
{
GLfloat nRange = 200.0f;
glViewport(0, 0, ClientWidth, ClientHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (ClientWidth <= ClientHeight)
glOrtho(-nRange, nRange, -nRange*ClientHeight/ClientWidth,
nRange*ClientHeight/ClientWidth, -nRange, nRange);
else
glOrtho(-nRange*ClientWidth/ClientHeight, nRange*ClientWidth/ClientHeight,
-nRange, nRange, -nRange, nRange);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
//---------------------------------------------------------------------------
Original Post : http://neodreamer-dev.tistory.com/269
Subscribe to:
Posts
(
Atom
)