Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » blit does not work under wxwidgets

This thread is locked; no one can reply to it. rss feed Print
blit does not work under wxwidgets
mail frank
Member #6,213
September 2005

I've managed to write a allegro program under wxwidgets for windows. My program is just load a bmp file and display on a wxWindow by Allegro. Unfortunately there are some functions does not work such as blit,install_keyboard etc. Here is part of my code: ( for complete source code, please refer to the attachment.)

1//----------------------
2// main.cpp
3//----------------------
4#include "main.h"
5#include "wxallegwin.h"
6#include "ResourceMgr.h"
7 
8int idMenuQuit = wxNewId();
9int idMenuAbout = wxNewId();
10 
11BEGIN_EVENT_TABLE(MyFrame, wxFrame)
12 EVT_MENU(idMenuQuit, MyFrame::OnQuit)
13 EVT_MENU(idMenuAbout, MyFrame::OnAbout)
14 EVT_PAINT(MyFrame::OnPaint)
15END_EVENT_TABLE()
16 
17MyFrame::MyFrame(wxFrame *frame, const wxString& title)
18 : wxFrame(frame, -1, title),m_pResMgr(NULL)
19{
20 wxMenuBar* mbar = new wxMenuBar();
21 wxMenu* fileMenu = new wxMenu(_(""));
22 fileMenu->Append(idMenuQuit, _("&Quit\tAlt-F4"), _("Quit the application"));
23 mbar->Append(fileMenu, _("&File"));
24 
25 wxMenu* helpMenu = new wxMenu(_(""));
26 helpMenu->Append(idMenuAbout, _("&About\tF1"), _("Show info about this application"));
27 mbar->Append(helpMenu, _("&Help"));
28 
29 SetMenuBar(mbar);
30 
31 CreateToolBar(wxTB_HORIZONTAL,-1);
32 SetClientSize(640,480);
33 m_pMyWin = new wxAllegWin(this,-1,wxPoint(0,0),GetSize(),0,"Allegro Win");
34 m_pMyWin->Install();
35 wxBoxSizer* bs = new wxBoxSizer(wxVERTICAL);
36 bs->Add(m_pMyWin,1,wxTOP|wxLEFT|wxBOTTOM|wxRIGHT|wxALIGN_CENTER|wxEXPAND|wxFIXED_MINSIZE,1);
37 SetSizer(bs);
38 SetAutoLayout(true);
39 Layout();
40 
41}
42 
43MyFrame::~MyFrame()
44{
45 m_pMyWin->Uninstall();
46 delete m_pMyWin;
47}
48 
49void MyFrame::OnQuit(wxCommandEvent& event)
50{
51 Close();
52}
53 
54void MyFrame::OnAbout(wxCommandEvent& event)
55{
56}
57 
58void MyFrame::OnPaint(wxPaintEvent& event)
59{
60 m_pMyWin->Rendering();
61 event.Skip();
62}
63 
64// ------------------------------------
65// wxAllegWin.cpp
66// ------------------------------------
67#include "wxallegwin.h"
68#include "ResourceMgr.h"
69 
70wxAllegWin::wxAllegWin(wxWindow* parent, wxWindowID id,
71 const wxPoint& pos,const wxSize& size,long style,
72 const wxString& name)
73 : wxWindow(parent,id,pos,size,style,name),
74 m_pFrameBuf(NULL),
75 m_bInstalled(false)
76{
77}
78 
79wxAllegWin::~wxAllegWin()
80{
81}
82 
83bool wxAllegWin::Install()
84{
85 if ( m_bInstalled )
86 return false;
87 
88 int w,h;
89 GetClientSize(&w,&h);
90 
91 /* the DirectX windowed driver requires the width to be a multiple of 4 */
92 w &= ~3;
93 
94#ifdef __GNUWIN32__
95 win_set_window((HWND)GetHandle());
96#endif
97 
98 /* initialize the library */
99 if (allegro_init() != 0)
100 {
101 // throw exception
102 }
103 
104 install_timer();
105 // Question: install_keyboard doesn't work
106 // install_keyboard();
107 install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL);
108 
109 set_color_depth(desktop_color_depth());
110 
111 /* install the DirectX windowed driver */
112 if (set_gfx_mode(GFX_DIRECTX_WIN, w, h, 0, 0) != 0)
113 {
114 wxMessageBox( "Unable the set the graphics mode.", "Error!",
115 wxOK | wxICON_INFORMATION );
116 }
117 
118 // create a bitmap buffer
119// m_pFrameBuf=create_bitmap(m_iWidth,m_iHeight);
120// clear_to_color(m_pFrameBuf, makecol(255, 255, 0));
121 
122 m_bInstalled = true;
123 
124 return true;
125}
126 
127void wxAllegWin::Uninstall()
128{
129// if ( m_pFrameBuf)
130// destroy_bitmap(m_pFrameBuf);
131 
132 allegro_exit();
133 
134 m_bInstalled = false;
135}
136 
137void wxAllegWin::Rendering()
138{
139 if ( m_bInstalled )
140 {
141 DrawBackground();
142 
143 // Question: doesn't work
144 //vsync();
145 //blit(m_pFrameBuf,screen,0,0,0,0,m_iWidth,m_iHeight);
146 }
147}
148 
149void wxAllegWin::DrawBackground()
150{
151 AL_BITMAP* bmp = load_pcx("allegro.pcx",NULL);
152 
153 if ( bmp )
154 {
155 // Question: blit does not work
156 //blit(bmp,screen,0,0,0,0,m_iWidth,m_iHeight);
157 acquire_screen();
158 draw_sprite(screen, bmp, 0, 0);
159 // Question: stretch_sprite does not work either
160 //stretch_sprite(screen, bmp, 0, 0,m_iWidth,m_iHeight);
161 release_screen();
162 }
163}

Can anybody advise?

Michael Faerber
Member #4,800
July 2004
avatar

What is the effect? Is there just a black window, or does the program crash ...?

--
"The basic of informatics is Microsoft Office." - An informatics teacher in our school
"Do you know Linux?" "Linux? Isn't that something for visually impaired people?"

Felipe Maia
Member #6,190
September 2005
avatar

Install keyboard probably will not work because of wxWidgets way of mapping keyboard itself. Your code is broke on the DrawBackground, a mass memoryleak, I don't know why it's not drawing, but the evt_Paint isn't sent all the time, so if you probably resize the window, the bitmap will show.

BAF
Member #2,981
December 2002
avatar

wxWidgets doesn't do anything special with the keyboard AFAIK, it just uses the messages from Windows, like any other GUI.

mail frank
Member #6,213
September 2005

I think wxWidgets is just us win32 api if running in Windows. I don't know why the behalf of wxWidgets is so different. I just copy the idea of dxwindow.c under Allegro test.

The behalf of my code is:
1.The blit is just showing a black screen.
2.The following code is just crashing:
AL_BITMAP* b = create_video_bitmap(m_iWidth, m_iHeight);
draw_sprite(b, bmp, 0, 0);
show_video_bitmap(b);
3.The stretch_sprite is showing a black screen.
4.After install_keyboard the program will run but will not be displayed.

BAF
Member #2,981
December 2002
avatar

Why are you using a directx window with wx? Why not just install_allegro with SYSTEM_NONE, then run graphics blitting to the wx window? Search the forums, in one of the wx threads I posted my code for that.

mail frank
Member #6,213
September 2005

The reason why I'm using Directx win is that I believe the performance should be better. Because I have quite a few sprite animations. The reason why I'm using it under wx is that I like its GUI.

When you say use SYSTEM_NOTE, can I still use draw_sprite or blit functions or do you mean to use something like blit_to_hdc? How's the performance?

Go to: