Hello,
I have successfully drawn my pixels using glDrawPixels with the GLUT code. I am now converting my code to MFC so I can use a menu system and GUI. I cannot get my glDrawPixels() function to draw the image. I think it has to do with my window atributes. Does anyone have any example MFC code that only draws 2D pixels to the screen. My text is showing up so I think I am doing something right. Maybe I am mixing mfc and opengl improperly?
I also need to know how to initially size my window to 512x512 in MFC.
void CFPA_ViewerView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
glShadeModel(GL_FLAT);
glEnable( GL_DOUBLEBUFFER );
glEnable( GL_RGB );
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glClear(GL_COLOR_BUFFER_BIT);
}
void CFPA_ViewerView::OnDraw(CDC* pDC)
{
CFPA_ViewerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
HWND hWnd = GetSafeHwnd();
HDC hDC = ::GetDC(hWnd);
glClearColor (1.0f, 1.0f, 1.0f, 1.0f);
unsigned int val=0;
char str[32];
static int ydelta=25;
glRasterPos2i(0, 0);
glClear(GL_COLOR_BUFFER_BIT);
glDrawPixels(row_size-translate_x,
row_size-translate_y, GL_RGB,
GL_UNSIGNED_BYTE, checkImage); //
glPixelZoom( zoom_factor, zoom_factor );
if( display_text == 1 )
{
int yval = ydelta;
sprintf( str, “Time: %.6lf sec”, current_time );
TextOut( hDC, 10, yval, str, strlen( str ) );
yval += ydelta;
sprintf( str, "Pixel Value: %.3lf, Zoom: %.3lf", pow(display_pixel_value, 0.3333333), zoom_factor );
TextOut( hDC, 10, yval, str, strlen( str ) ); yval += ydelta;
}
SwapBuffers(hDC);
}
wglMakeCurrent(pDC->m_hDC, NULL);
// Release
ReleaseDC(pDC);
}
int CFPA_ViewerView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL,
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
};
CDC* pDC=GetDC();
int pixelFormat = ChoosePixelFormat(pDC->m_hDC, &pfd);
SetPixelFormat(pDC->m_hDC, pixelFormat, &pfd);
m_hRC = wglCreateContext(pDC->m_hDC);
return 0;
}
Thanks,
Tim