Click here to Skip to main content
15,909,242 members
Home / Discussions / Graphics
   

Graphics

 
QuestionSaving image files in ARGB format (with transparency) Pin
pbalaga5-Sep-08 9:23
pbalaga5-Sep-08 9:23 
QuestionDirectX, OpenGL, WPF or XNA? Pin
Uri912-Sep-08 8:18
Uri912-Sep-08 8:18 
AnswerRe: DirectX, OpenGL, WPF or XNA? Pin
John_Adams2-Sep-08 19:26
John_Adams2-Sep-08 19:26 
GeneralRe: DirectX, OpenGL, WPF or XNA? Pin
Uri913-Sep-08 2:19
Uri913-Sep-08 2:19 
GeneralRe: DirectX, OpenGL, WPF or XNA? Pin
Pete O'Hanlon4-Sep-08 10:49
mvePete O'Hanlon4-Sep-08 10:49 
QuestionHow can I have OpenGL in MFC SDI and Dialog at the same time Pin
Member 44253871-Sep-08 3:16
Member 44253871-Sep-08 3:16 
AnswerRe: How can I have OpenGL in MFC SDI and Dialog at the same time Pin
Tim Craig1-Sep-08 19:16
Tim Craig1-Sep-08 19:16 
GeneralRe: How can I have OpenGL in MFC SDI and Dialog at the same time Pin
Member 44253872-Sep-08 0:28
Member 44253872-Sep-08 0:28 
Hi thank you very much for your help. I manage to run OpenGL in My dialog, as you told me Smile | :) .
This is running ok in the SDI (I checked and on mouse move, mouse click is ok, is entering to the functions). But In the dialog, only mouse move works, mouse click is not working (he is not entering to the functions). When I do click inside the dialog I get
" Debug Assertion Failed
File:viewcore.cpp
Line: 249
"
Any help will be really good. Thank you again
This is how I add it to the dialog

BOOL CAboutDlg::OnInitDialog() 
{ CDialog::OnInitDialog();
  // TODO: Add extra initialization here
 CRect rect;

  // Get size and position of the picture control
  GetDlgItem(IDC_OPENGL)->GetWindowRect(rect);
  z0Lv_openGL = new COpenGLView();
  // Convert screen coordinates to client coordinates
  ScreenToClient(rect);

  // Create OpenGL Control window
  z0Lv_openGL->oglCreate(rect, this);

  return TRUE; 
}



This is my is COpenGLView.h

/////////////////////////////////////////////////////////////////////////////
// COpenGLView view

#include 
#include "MyView.h"

// This view encapsulates a personalized 3D view
class COpenGLView : public CView
{
public:
	COpenGLView();           // protected constructor used by dynamic creation
	virtual ~COpenGLView();


  /*MEMBER oglCreate_________________________________________________________*/
  void oglCreate(CRect rect, CWnd *parent);

protected:
	DECLARE_DYNCREATE(COpenGLView)

// Attributes
protected:
	CDC*			m_pDC;
	HGLRC			m_hRC;
	GLUquadricObj*	m_quadric;

	double			m_rotation[3];

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(COpenGLView)
	protected:
	virtual void OnDraw(CDC* pDC);      // overridden to draw this view
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	//}}AFX_VIRTUAL

// Implementation
protected:
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

	// Generated message map functions
protected:
	void SetupPixelFormat();
	void InitGL();
	//{{AFX_MSG(COpenGLView)
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg void OnDestroy();
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};


My COpenGLView.cpp

/////////////////////////////////////////////////////////////////////////////
// COpenGLView

IMPLEMENT_DYNCREATE(COpenGLView, CView)

COpenGLView::COpenGLView()
{
}

COpenGLView::~COpenGLView()
{
}


BEGIN_MESSAGE_MAP(COpenGLView, CView)
	//{{AFX_MSG_MAP(COpenGLView)
	ON_WM_CREATE()
	ON_WM_ERASEBKGND()
	ON_WM_DESTROY()
	ON_WM_SIZE()
	ON_WM_TIMER()
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONDBLCLK()
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COpenGLView drawing

void COpenGLView::OnDraw(CDC* pDC)
{static double dLv_d=0.5;
  dLv_d =dLv_d+1.0;
	wglMakeCurrent(m_pDC->GetSafeHdc(), m_hRC);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	//glLoadIdentity();

	glRotated(m_rotation[0], 1.0, 0.0, 0.0);
	glRotated(m_rotation[1], 0.0, 1.0, 0.0);
	glRotated(m_rotation[2], 0.0, 0.0, 1.0);

	glPushMatrix();

	glColor3f(1.0f, 0.1f, 0.5f);
	gluCylinder(m_quadric, 1.0, 1.0, 1.0, 16, 16);
	gluDisk(m_quadric, 0.0, 1.0, 16, 1);
	glTranslated(dLv_d, 0.0, 1.0);
	gluDisk(m_quadric, 0.0, 1.0, 16, 1);

	glPopMatrix();
	
	SwapBuffers(m_pDC->GetSafeHdc());
}

/////////////////////////////////////////////////////////////////////////////
// COpenGLView diagnostics

#ifdef _DEBUG
void COpenGLView::AssertValid() const
{
	CView::AssertValid();
}

void COpenGLView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// COpenGLView message handlers

int COpenGLView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	InitGL();
	
	return 0;
}

BOOL COpenGLView::PreCreateWindow(CREATESTRUCT& cs) 
{
	cs.style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
	
	return CView::PreCreateWindow(cs);
}

void COpenGLView::InitGL()
{ 
	m_pDC = new CClientDC(this);
	
	SetupPixelFormat();

	m_hRC = wglCreateContext(m_pDC->GetSafeHdc());

	wglMakeCurrent(m_pDC->GetSafeHdc(), m_hRC);

	glClearColor(0.0f, 0.0f, 0.5f, 0.0f);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_LIGHTING);
	
	glEnable(GL_LIGHT0);
	
	GLfloat color[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
	GLfloat lightPos[4] = {3.0f, 3.0f, 3.0f, 1.0f };

	glLightfv(GL_LIGHT0, GL_AMBIENT, color);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, color);
	glLightfv(GL_LIGHT0, GL_SPECULAR, color);
	glLightfv(GL_LIGHT0, GL_POSITION, lightPos);

	m_quadric = gluNewQuadric();

	for(int i=0; i<3; i++) {
		m_rotation[i] = (((double) rand() / (double) RAND_MAX) * 2.0) - 1.0;
	}

	//SetTimer(m_idView, 10, NULL);
}

void COpenGLView::SetupPixelFormat()
{
	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,
		16,
		0,
		0,
		PFD_MAIN_PLANE,
		0,
		0, 0, 0,
	};

	int pixelformat = ChoosePixelFormat(m_pDC->GetSafeHdc(), &pfd);
	SetPixelFormat(m_pDC->GetSafeHdc(), pixelformat, &pfd);
}

BOOL COpenGLView::OnEraseBkgnd(CDC* pDC) 
{
	return TRUE;
}


void COpenGLView::OnDestroy() 
{
	wglMakeCurrent(NULL, NULL);
	wglDeleteContext(m_hRC);
	if(m_pDC) delete m_pDC;

	gluDeleteQuadric(m_quadric);

	CView::OnDestroy();
}

void COpenGLView::OnSize(UINT nType, int cx, int cy) 
{
	CView::OnSize(nType, cx, cy);
	
	wglMakeCurrent(m_pDC->GetSafeHdc(), m_hRC);
	glViewport(0, 0, cx, cy);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0, (double) cx / (double) cy, 0.1, 1000.0);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
}

void COpenGLView::OnTimer(UINT nIDEvent) 
{
	Invalidate();
	
	CView::OnTimer(nIDEvent);
}



/*MEMBER oglCreate_________________________________________________________*/
void COpenGLView::oglCreate(CRect rect, CWnd *parent)
{
   CString className = AfxRegisterWndClass(CS_HREDRAW |
      CS_VREDRAW | CS_OWNDC, NULL,
      (HBRUSH)GetStockObject(BLACK_BRUSH), NULL);

   CreateEx(0, className, "OpenGL", WS_CHILD | WS_VISIBLE |
            WS_CLIPSIBLINGS | WS_CLIPCHILDREN, rect, parent, 0);

   // Set initial variables' values
   //m_oldWindow    = rect;
   //m_originalRect = rect;

   //hWnd = parent;
}


void COpenGLView::OnMouseMove(UINT nFlags, CPoint point) 
{
		Invalidate();
	

	CView::OnMouseMove(nFlags, point);
}


void COpenGLView::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
	CView::OnLButtonDblClk(nFlags, point);
}

void COpenGLView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
	CView::OnLButtonDown(nFlags, point);
}

void COpenGLView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
	CView::OnLButtonUp(nFlags, point);
}

GeneralRe: How can I have OpenGL in MFC SDI and Dialog at the same time Pin
Tim Craig2-Sep-08 18:11
Tim Craig2-Sep-08 18:11 
GeneralRe: How can I have OpenGL in MFC SDI and Dialog at the same time Pin
Member 44253874-Sep-08 7:51
Member 44253874-Sep-08 7:51 
QuestionDrawing a big topographic map in its own coordinates Pin
ianhunt0131-Aug-08 23:36
ianhunt0131-Aug-08 23:36 
QuestionGif animation Pin
The Only Nock28-Aug-08 13:14
The Only Nock28-Aug-08 13:14 
AnswerRe: Gif animation Pin
Mark Salsbery29-Aug-08 11:01
Mark Salsbery29-Aug-08 11:01 
GeneralRe: Gif animation Pin
The Only Nock31-Aug-08 15:56
The Only Nock31-Aug-08 15:56 
GeneralRe: Gif animation Pin
Mark Salsbery1-Sep-08 7:28
Mark Salsbery1-Sep-08 7:28 
QuestionDrawing failed? Pin
Tapio Grönfors28-Aug-08 1:19
Tapio Grönfors28-Aug-08 1:19 
AnswerRe: Drawing failed? Pin
Mark Salsbery28-Aug-08 6:21
Mark Salsbery28-Aug-08 6:21 
GeneralRe: Drawing failed? Pin
Tapio Grönfors28-Aug-08 19:05
Tapio Grönfors28-Aug-08 19:05 
GeneralRe: Drawing failed? Pin
Mark Salsbery29-Aug-08 5:14
Mark Salsbery29-Aug-08 5:14 
AnswerRe: Drawing failed? Pin
Pete O'Hanlon4-Sep-08 10:48
mvePete O'Hanlon4-Sep-08 10:48 
QuestionPiggyback image /overlapped image Pin
sujtha27-Aug-08 23:12
sujtha27-Aug-08 23:12 
QuestionRe: Piggyback image /overlapped image Pin
Mark Salsbery28-Aug-08 6:20
Mark Salsbery28-Aug-08 6:20 
Questionicon file contaning more than one version of the icon Pin
The Only Nock26-Aug-08 17:35
The Only Nock26-Aug-08 17:35 
AnswerRe: icon file contaning more than one version of the icon Pin
The Only Nock14-Sep-08 6:41
The Only Nock14-Sep-08 6:41 
QuestionDrawing to a checkBox (button mode) using Graphics Pin
The Only Nock26-Aug-08 16:14
The Only Nock26-Aug-08 16:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.