Code: Select all
Compiler: Default compiler
Building Makefile: "M:\Code\CPP\mayhem\Makefile.win"
Finding dependencies for file: M:\Code\CPP\mayhem\base.cpp
Executing make...
make.exe -f "M:\Code\CPP\mayhem\Makefile.win" all
g++.exe -c base.cpp -o build/base.o -I"lib/gcc/mingw32/3.4.2/include" -I"include/c++/3.4.2/backward" -I"include/c++/3.4.2/mingw32" -I"include/c++/3.4.2" -I"include" -I"E:/Dev-Cpp/lib/wx/include/msw-ansi-release-static-2.6" -I"E:/Dev-Cpp/include/wx-2.6" -I"E:\Dev-Cpp\\include\..\lib\wx\include\msw-ansi-release-static-2.6" -I"E:\Dev-Cpp\\include\wx-2.6" -D__WXMSW__ -mthreads -DNO_GCC_PRAGMA -fexpensive-optimizations -O3 -march=i686 -msse2
windres.exe -i mayhem_private.rc --input-format=rc -o build/mayhem_private.res -O coff --include-dir E:/Dev-Cpp/include/wx-2.6
g++.exe build/base.o build/mayhem_private.res -o "build\mayhem.exe" -L"lib" -mwindows -mthreads -Wl,--subsystem,windows -mwindows -lwx_msw-2.6 -lpng -lz -ljpeg -ltiff -lz -lrpcrt4 -loleaut32 -lole32 -luuid -lodbc32 -lole32 -loleaut32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lcomdlg32 -lctl3d32 -ladvapi32 -lwsock32 -lgdi32 -lopengl32 -s -march=i686 -msse2
build/base.o(.text+0x5b7):base.cpp: undefined reference to `wxGLCanvas::wxGLCanvas(wxWindow*, int, wxPoint const&, wxSize const&, long, wxString const&, int*, wxPalette const&)'
build/base.o(.text+0x5eb):base.cpp: undefined reference to `wxGLCanvas::SetCurrent()'
build/base.o(.text+0x619):base.cpp: undefined reference to `wxGLCanvas::~wxGLCanvas()'
build/base.o(.text+0x78d):base.cpp: undefined reference to `wxGLCanvas::wxGLCanvas(wxWindow*, int, wxPoint const&, wxSize const&, long, wxString const&, int*, wxPalette const&)'
build/base.o(.text+0x7c1):base.cpp: undefined reference to `wxGLCanvas::SetCurrent()'
build/base.o(.text+0x866):base.cpp: undefined reference to `wxGLCanvas::~wxGLCanvas()'
build/base.o(.text+0x9c7):base.cpp: undefined reference to `wxGLCanvas::wxGLCanvas(wxWindow*, int, wxPoint const&, wxSize const&, long, wxString const&, int*, wxPalette const&)'
build/base.o(.text+0x9fb):base.cpp: undefined reference to `wxGLCanvas::SetCurrent()'
build/base.o(.text+0xa29):base.cpp: undefined reference to `wxGLCanvas::~wxGLCanvas()'
build/base.o(.text+0xa53):base.cpp: undefined reference to `wxGLCanvas::~wxGLCanvas()'
build/base.o(.text+0xa73):base.cpp: undefined reference to `wxGLCanvas::~wxGLCanvas()'
build/base.o(.text+0xa94):base.cpp: undefined reference to `wxGLCanvas::~wxGLCanvas()'
build/base.o(.text+0xc65):base.cpp: undefined reference to `wxGLCanvas::SetCurrent()'
build/base.o(.text+0xc73):base.cpp: undefined reference to `wxGLCanvas::SwapBuffers()'
build/base.o(.text+0xd35):base.cpp: undefined reference to `wxGLCanvas::OnSize(wxSizeEvent&)'
build/base.o(.text+0xd62):base.cpp: undefined reference to `wxGLCanvas::SetCurrent()'
build/base.o(.text+0x1679):base.cpp: undefined reference to `Mayhem::OnChar(wxKeyEvent&)'
build/base.o(.text+0x16b6):base.cpp: undefined reference to `Mayhem::OnMouseEvent(wxMouseEvent&)'
build/base.o(.text+0x190b):base.cpp: undefined reference to `Mayhem::OnEraseBackground(wxEraseEvent&)'
build/base.o(.rdata$_ZTV6Mayhem[vtable for Mayhem]+0x8):base.cpp: undefined reference to `wxGLCanvas::GetClassInfo() const'
build/base.o(.rdata+0x0):base.cpp: undefined reference to `wxGLCanvas::sm_eventTable'
collect2: ld returned 1 exit status
make.exe: *** [build/mayhem.exe] Error 1
Execution terminated
Code: Select all
#ifndef __BASE_H
#define __BASE_H
#define MAXPLAYERS 16
#define SHIPSDIR "ships/"
#define SHIPSMAXLINES 64
#define SHIPSDEFAULTAMMO 500
#define SHIPSDEFAULTFUEL 100
#define SHIPSDEFAULTHEALTH 100
#define MAPSDIR "maps/"
typedef struct
{
int x[2];
int y[2];
} LINE;
typedef struct
{
LINE l[SHIPSMAXLINES];
} SHIPMODEL;
typedef struct
{
int r;
int g;
int b;
} COLOUR;
class Ship;
class Player;
class Game;
class Mayhem;
class MyApp : public wxApp
{
public:
virtual bool OnInit();
private:
void InitFrame();
};
class MainFrame : public wxFrame
{
public:
MainFrame(wxFrame *frame, const wxString& title, int xpos, int ypos,
int width, int height);
~MainFrame();
Mayhem *gp_GLCanvas;
private:
void OnExit(wxCommandEvent& event);
DECLARE_EVENT_TABLE()
};
#if wxUSE_GLCANVAS
class Mayhem : public wxGLCanvas
{
public:
Mayhem(wxWindow *parent, wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = 0,
const wxString& name = _T("Mayhem"), int *gl_attrib = NULL);
~Mayhem();
void render();
void drawShip(const Ship theShip, GLint originX, GLint originY,
GLfloat angle);
//void drawMap(const Map theMap);
void OnPaint(wxPaintEvent& event);
void OnSize(wxSizeEvent& event);
void OnEraseBackground(wxEraseEvent& event);
void OnChar(wxKeyEvent& event);
void OnMouseEvent(wxMouseEvent& event);
void OnIdleLoop(wxIdleEvent& event);
DECLARE_EVENT_TABLE()
};
#endif // #if wxUSE_GLCANVAS
class Ship
{
public:
Ship(wxChar *model);
~Ship();
int getRotation() { return m_rotation; }
int getPosX() { return m_posX; }
int getPosY() { return m_posY; }
void loadModel(wxChar *model);
SHIPMODEL m_shipModel;
COLOUR m_colour;
private:
int m_rotation;
int m_posX;
int m_posY;
int m_ammo;
int m_fuel;
int m_health;
};
class Player
{
public:
Player(wxString name, wxChar *model);
~Player();
Ship *m_ship;
wxString m_name;
private:
};
class Game
{
public:
Game();
~Game();
int getPlayerCount() { return m_playerCount; }
void addPlayer(Player *new_player);
void remPlayer(int playerNum);
private:
int m_playerCount;
Player *m_players[MAXPLAYERS];
};
#endif // __BASE_H
Code: Select all
#ifdef __GNUG__
#pragma implementation
#pragma interface
#endif
#include <wx/wxprec.h>
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#if !wxUSE_GLCANVAS
#error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library"
#endif
//Standard C/C++
#include <stdio.h>
//OpenGL
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
//WxWidgets
#include <wx/glcanvas.h>
#include "base.h"
IMPLEMENT_APP(MyApp);
bool MyApp::OnInit()
{
InitFrame();
return true;
}
void MyApp::InitFrame()
{
MainFrame* frame = new MainFrame(0L, "Mayhem", 0, 0, 640, 480);
frame->gp_GLCanvas = new Mayhem(frame, wxID_ANY, wxDefaultPosition,
wxDefaultSize, 0, "Mayhem");
frame->Show(true);
frame->Maximize(true);
}
BEGIN_EVENT_TABLE(MainFrame, wxFrame)
EVT_MENU(wxID_EXIT, MainFrame::OnExit)
END_EVENT_TABLE()
MainFrame::MainFrame(wxFrame *frame, const wxString& title, int xpos, int ypos,
int width, int height)
: wxFrame(frame, wxID_ANY, title, wxPoint(xpos, ypos), wxSize(width, height))
{
gp_GLCanvas = NULL;
}
MainFrame::~MainFrame()
{
}
void MainFrame::OnExit(wxCommandEvent& event)
{
Close(true);
}
BEGIN_EVENT_TABLE(Mayhem, wxGLCanvas)
EVT_PAINT(Mayhem::OnPaint)
EVT_SIZE(Mayhem::OnSize)
EVT_CHAR(Mayhem::OnChar)
EVT_MOUSE_EVENTS(Mayhem::OnMouseEvent)
EVT_ERASE_BACKGROUND(Mayhem::OnEraseBackground)
EVT_IDLE(Mayhem::OnIdleLoop)
END_EVENT_TABLE()
Mayhem::Mayhem(wxWindow *parent, wxWindowID id,
const wxPoint& pos, const wxSize& size, long style,
const wxString& name, int* gl_attrib)
: wxGLCanvas(parent, id, pos, size, style|wxFULL_REPAINT_ON_RESIZE, name, gl_attrib)
{
parent->Show(true);
SetCurrent();
/*//Test code
Player player1 = new Player(_("GotenXiao"));
player1.m_ship.loadModel(1);
addPlayer(player1);
//End of test code*/
}
Mayhem::~Mayhem()
{
}
void Mayhem::render() {
glFlush();
wxSleep(5);
}
void Mayhem::drawShip(const Ship theShip, GLint originX, GLint originY,
GLfloat angle)
{
int i;
GLint x1, x2, y1, y2;
glPushMatrix();
glColor3i(theShip.m_colour.r, theShip.m_colour.g, theShip.m_colour.b);
glRotatef(angle, 0.0f, 0.0f, 1.0f);
glBegin(GL_LINES);
for (i=0;i<64;i++) {
if (theShip.m_shipModel.l[i].x[0] > 0
&& theShip.m_shipModel.l[i].x[1] > 0
&& theShip.m_shipModel.l[i].y[0] > 0
&& theShip.m_shipModel.l[i].y[1] > 0)
{
x1 = theShip.m_shipModel.l[i].x[0] + originX;
y1 = theShip.m_shipModel.l[i].y[0] + originY;
x2 = theShip.m_shipModel.l[i].x[1] + originX;
y2 = theShip.m_shipModel.l[i].y[1] + originY;
glVertex2i(x1, y1);
glVertex2i(x2, y2);
}
}
glEnd();
glPopMatrix();
}
/*
void Mayhem::drawMap(const Map theMap)
{
}
*/
void Mayhem::OnPaint(wxPaintEvent& WXUNUSED(event))
{
// This is a dummy, to avoid an endless succession of paint messages.
// OnPaint handlers must always create a wxPaintDC.
wxPaintDC dc(this);
#ifndef __WXMOTIF__
if (!GetContext()) return;
#endif
SetCurrent();
SwapBuffers();
}
void Mayhem::OnSize(wxSizeEvent& event)
{
// this is also necessary to update the context on some platforms
wxGLCanvas::OnSize(event);
// set GL viewport (not called by wxGLCanvas::OnSize on all platforms...)
int w, h;
GetClientSize(&w, &h);
#ifndef __WXMOTIF__
if (GetContext())
#endif
{
SetCurrent();
glViewport(0, 0, (GLint) w, (GLint) h);
}
}
void Mayhem::OnIdleLoop(wxIdleEvent& event)
{
this->render();
}
Ship::Ship(wxChar *model)
{
m_rotation = 0;
m_posX = 0;
m_posY = 0;
m_ammo = SHIPSDEFAULTAMMO;
m_fuel = SHIPSDEFAULTFUEL;
m_health = SHIPSDEFAULTHEALTH;
loadModel(model);
}
Ship::~Ship()
{
}
void Ship::loadModel(wxChar *model)
{
const char *filename = *SHIPSDIR + *model + ".shp";
FILE *f = fopen(filename, "r");
if (!f) {
wxString msg = _T("Couldn't read ");
msg += filename;
wxMessageBox(msg);
return;
}
int lines = 0;
while (!feof(f) && lines < SHIPSMAXLINES) {
fscanf(f, "[%i %i][%i %i]",
m_shipModel.l[lines].x[0],
m_shipModel.l[lines].y[0],
m_shipModel.l[lines].x[1],
m_shipModel.l[lines].y[1]);
lines++;
}
fclose(f);
}
Player::Player(wxString name, wxChar *model)
{
m_name = name;
m_ship = new Ship(model);
}
Player::~Player()
{
}
Game::Game()
{
}
Game::~Game()
{
}
void Game::addPlayer(Player *new_player)
{
m_playerCount++;
m_players[m_playerCount] = new_player;
}
void Game::remPlayer(int playerNum)
{
m_playerCount--;
delete m_players[playerNum];
m_players[playerNum] = NULL;
}