Ejemplo n.º 1
0
/*******************************************************************
**	OpenGLの初期化
*******************************************************************/
bool OpenGL::InitOpenGL(HWND hWnd)
{

	if ( !::IsWindow(hWnd) )
	{
		fprintf(stderr, "OpenGL::CreateOpenGL Invalid Window Handle");
		return false;
	}

	m_hWnd	= hWnd;
	m_hDC	= ::GetDC(hWnd);

	if ( !SetWindowPixelFormat() )
	{
		fprintf(stderr, "OpenGL::SetWindowPixelFormat Error");
		return false;
	}

	if ( !CreateGLContext() )
	{
		fprintf(stderr, "OpenGL::CreateGLContext Error");
		return false;
	}


	return (true);
}
Ejemplo n.º 2
0
bool COpenGL::InitOpenGL (HWND hWnd)
{
  //## begin COpenGL::InitOpenGL%40E265430348.body preserve=yes
//	bool COpenGL::InitOpenGL(HWND hWnd)
{
	if (!::IsWindow(hWnd))
		return false;

	m_hWnd = hWnd;
	m_hDC = ::GetDC(m_hWnd);
	
	if(!SetWindowPixelFormat())
		return false;
	if(!CreateViewGLContext())
		return false;
	
    //glClearColor(140.0f/255, 195.0f/255, 245.0f/155, 1.0f);
    //glClearColor(0.0, 0.25, 0.5, 0.0);
	glClearColor(0.0, 0.0, 0.0, 0.0);
	glClearDepth(1.0);
	glEnable(GL_DEPTH_TEST);
	RasterFont();
	//BulidFont();
	return true;
}

  //## end COpenGL::InitOpenGL%40E265430348.body
}
Ejemplo n.º 3
0
int CEasyGenView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CView::OnCreate(lpCreateStruct) == -1)
	{
		return -1;
	}

	HWND hWnd = GetSafeHwnd();
	HDC  hDC  = ::GetDC(hWnd);

	if (SetWindowPixelFormat(hDC) == FALSE)
	{
		return 0;
	}

	if (CreateViewGLContext(hDC) == FALSE)
	{
		return 0;
	}

	glEnable(GL_NORMALIZE);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);

	glPolygonOffset(-0.8f, -0.8f);

	glClearColor(m_ClearColorRed, m_ClearColorGreen, m_ClearColorBlue, 1.0f);

	glClearDepth(1.0f);

	// Lights, material properties
	GLfloat ambientProperties[]  = { 0.7f, 0.7f, 0.7f, 1.0f };
	GLfloat diffuseProperties[]  = { 0.8f, 0.8f, 0.8f, 1.0f };
	GLfloat specularProperties[] = { 1.0f, 0.5f, 1.0f, 1.0f };
//	GLfloat LightPosition[]= { 0.0f, 5.0f, -5.0f, 1.0f };				 // Light Position ( NEW )

	m_LightPos[0] = 0.f;
	m_LightPos[1] = 0.f;
	m_LightPos[2] = 0.f;
	m_LightPos[3] = 1.f;

	m_LightDir[0] = 0.f;
	m_LightDir[1] = 0.f;
	m_LightDir[2] = -1.f;
	m_LightDir[3] = 1.f;

	glLightfv(GL_LIGHT1, GL_AMBIENT, ambientProperties);
	glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuseProperties);
	glLightfv(GL_LIGHT1, GL_SPECULAR, specularProperties);
	glLightfv(GL_LIGHT1, GL_POSITION, m_LightPos);           // Position The Light
	glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, m_LightDir);         // Position The Light
	glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, 1.0);

	SetTimer(1, 200, NULL);

	return 0;
}
Ejemplo n.º 4
0
//***************************************
// Init
//***************************************
int CStaticView::Init() 
{ 
	HWND hWnd = GetSafeHwnd();
	HDC hDC = ::GetDC(hWnd);

	if(SetWindowPixelFormat(hDC)==FALSE)
		return FALSE;
	
	if(CreateViewGLContext(hDC)==FALSE)
		return FALSE;

  glShadeModel(GL_FLAT);
	glEnable(GL_NORMALIZE);

	// Lights properties
  float	ambientProperties[]  = {0.7f, 0.7f, 0.7f, 1.0f};
	float	diffuseProperties[]  = {0.8f, 0.8f, 0.8f, 1.0f};
  float	specularProperties[] = {1.0f, 1.0f, 1.0f, 1.0f};
	
  glLightfv( GL_LIGHT0, GL_AMBIENT, ambientProperties);
  glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuseProperties);
  glLightfv( GL_LIGHT0, GL_SPECULAR, specularProperties);
  glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, 1.0);

	COLORREF color = GetSysColor(COLOR_3DFACE);
	float r = (float)GetRValue(color)/255.0f;
	float g = (float)GetGValue(color)/255.0f;
	float b = (float)GetBValue(color)/255.0f;
	glClearColor(r,g,b,1.0f);
  glClearDepth(1.0f);
	glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);

	// Perspective
	CRect rect;
	GetClientRect(&rect);
	double aspect = (rect.Height() == 0) ? 
		rect.Width() : (double)rect.Width()/(double)rect.Height();
	gluPerspective(45,aspect,0.1,1000.0);

	glPolygonMode(GL_FRONT,GL_LINE);
	glPolygonMode(GL_BACK,GL_LINE);

	// Antialiasing
	glEnable(GL_LINE_SMOOTH);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
	glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
	glLineWidth(1.1f);

	SetTimer(1,1,NULL);
	return 1;
}
Ejemplo n.º 5
0
LOGICAL COpenGL::InitGL(HDC hDC)
{
	m_hDC = hDC;
	if (SetWindowPixelFormat() == LOGICAL_FALSE)
		return LOGICAL_FALSE;
	
	if (CreateViewGLContext() == LOGICAL_FALSE)
		return LOGICAL_FALSE;

	MakeGLContextCurrent();
	OnSetDefaultOptions();
	OnInitialized();
	MakeGLContextNotCurrent();

	return LOGICAL_TRUE;
}
Ejemplo n.º 6
0
int Cab_mfcView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO:  在此添加您专用的创建代码
	//初始化
	HWND hWnd = GetSafeHwnd();
	m_hDC = ::GetDC(hWnd);
	//建立窗口格式
	if(SetWindowPixelFormat(m_hDC)==FALSE)
		return 0;
	//建立RC
	m_hRC = wglCreateContext(m_hDC);
	if(m_hRC==NULL)
		return 0;
	if(wglMakeCurrent(m_hDC,m_hRC)==FALSE)
		return 0;
	//初始化OpenGL的各个参数	
	glClearColor(0,0,0,1.0);

	//设置光照
	GLfloat light_ambient[]={0.3f,0.2f,0.5f};
	GLfloat light_diffuse[]={1.0f,1.0f,1.0f};
	GLfloat light_position[] = { 2.0f, 2.0f, 2.0f, 1.0f };


	glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
	glLightfv(GL_LIGHT0, GL_POSITION, light_position);

	glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);

	glColorMaterial(GL_FRONT_AND_BACK,GL_DIFFUSE);
	glEnable(GL_COLOR_MATERIAL);

	glDepthFunc(GL_LESS);
	glEnable(GL_DEPTH_TEST);

	//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	JIQIREN();
	SetTimer(0,10,NULL);
	//////////////////////////////////////////////////
	return 0;
}
Ejemplo n.º 7
0
void createWindow(LPTSTR title, float w, float h) {
	int flags = WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_OVERLAPPEDWINDOW;

	hwnd = CreateWindowEx(	WS_EX_APPWINDOW | WS_EX_WINDOWEDGE,
							WND_CLASS_NAME, title, flags,
							0, 0, w, h, 
							NULL, NULL, hinst, NULL);

	GetClientRect(hwnd, &win_rect);

	dc = GetDC(hwnd);
	SetWindowPixelFormat(dc);

	rc = wglCreateContext(dc);
	wglMakeCurrent(dc,rc);
	wglSwapIntervalEXT(1);
}
Ejemplo n.º 8
0
int CwindcView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;

	HWND hwnd = GetSafeHwnd();
	HDC hDC = ::GetDC(hwnd);
	if (FALSE == SetWindowPixelFormat(hDC))
	{
		return 0;
	}

	if (FALSE == CreateViewGLContext(hDC))
	{
		return 0;
	}

	return 0;
}
Ejemplo n.º 9
0
int CArMaXCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (COleControl::OnCreate(lpCreateStruct) == -1)
		return -1;

	// Set pixel format
	m_hDC = ::GetDC(m_hWnd);
  if(SetWindowPixelFormat(m_hDC))
  {
    m_hRC = wglCreateContext(m_hDC);
    if(m_hRC)
      wglMakeCurrent (m_hDC, m_hRC);
    else
      return 0;
  }
  
  InitScene();
 
	return 0;
}