Drawing bitmap by using glBitmap in wxGLCanvas Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
zhouhao
Earned some good credits
Earned some good credits
Posts: 144
Joined: Tue Dec 06, 2005 7:02 am

Drawing bitmap by using glBitmap in wxGLCanvas

Post by zhouhao »

I posted this question under general forum but nobody anwser me. I post here again:

I'm very new to OpenGL and I'm trying to show a bitmap in wxGLCanvas, but it shows a black screen. Here is my code:

GLubyte rasters[24] = {
0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
0xc0, 0x00, 0xff, 0x00, 0xff, 0x00, 0xc0, 0x00,
0xc0, 0x00, 0xc0, 0x00, 0xff, 0xc0, 0xff, 0xc0};


void CTestCanvas::OnPaint( wxPaintEvent& WXUNUSED(event) )
{
wxPaintDC dc(this);

#ifndef __WXMOTIF__
if (!GetContext()) return;
#endif

SetCurrent();

// Init OpenGL once, but after SetCurrent
if (!m_bGLInit)
{
InitGL();
m_bGLInit = true;
}

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-0.5f, 0.5f, -0.5f, 0.5f, 1.0f, 3.0f);
glMatrixMode(GL_MODELVIEW);

/* clear color and depth buffers */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glColor3f(0.0, 1.0, 1.0);
glRasterPos2f(20.0, 20.0);
glBitmap(10, 12, 0.0, 0.0, 12.0, 0.0, rasters);
glBitmap(10, 12, 0.0, 0.0, 12.0, 0.0, rasters);
glBitmap(10, 12, 0.0, 0.0, 12.0, 0.0, rasters);

glFlush();
SwapBuffers();
}

bool CGameConsole::InitGL()
{
SetCurrent();

glMatrixMode(GL_PROJECTION);
glFrustum(-0.5f, 0.5f, -0.5f, 0.5f, 1.0f, 3.0f);

/* position viewer */
glMatrixMode(GL_MODELVIEW);
glTranslatef(0.0f, 0.0f, -2.0f);

/* position object */
glRotatef(30.0f, 1.0f, 0.0f, 0.0f);
glRotatef(30.0f, 0.0f, 1.0f, 0.0f);

glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

return true;
}

Anything wrong with it?

Another question is can I use wxGLCanvas to show wxBitmap?

I found there is another issue on using wxGLCanvas. When I move the window by dragging the title bar, the wxGLCanvas window will not be repaint. I tried this on wxWidgets' sample program Cube. It also have this problem. Is this a bug of wxWidgets?
theigor
Experienced Solver
Experienced Solver
Posts: 78
Joined: Thu Jan 12, 2006 6:51 pm

Re: Drawing bitmap by using glBitmap in wxGLCanvas

Post by theigor »

zhouhao wrote:I found there is another issue on using wxGLCanvas. When I move the window by dragging the title bar, the wxGLCanvas window will not be repaint. I tried this on wxWidgets' sample program Cube. It also have this problem. Is this a bug of wxWidgets?
in your glcanvas event table you should add an EVT_IDLE(GLCanvas::OnIdle)

void GLCanvas::OnIdle(wxIdleEvent& WXUNUSED(event))
{
this->Refresh();
}

This should do the trick
Woesti
In need of some credit
In need of some credit
Posts: 1
Joined: Fri Oct 27, 2006 7:23 am

use the wxImage

Post by Woesti »

Hey,

I was looking for the same thing and found that if I make a wxBitmap and convert it to an wxImage. For an image there is a function that gives you an unsigned char pointer to the pixel array of the wxImage.

This pointer can be give to the function
glDrawPixels(img.GetWidth(),img.GetHeight(),GL_RGB,GL_UNSIGNED_BYTE,(GLubyte *)Pointer);


If you can find a way to give an alpha value to the pixels in the imagemap, pleas let me know.

Greetzzz.
Woesti
Post Reply