#include <wx/wx.h>
#include <wx/window.h>
#include "TSMain.h"
#include "sample.xpm"
#include <gl/gl.h>
#include <gl/glu.h>
#include "TSGameMain.h"
TSFrame* g_pFrame;
int g_KeyPort;
CMouseStat g_MousePort;
/*----------------------------------------------------------------
Implementation of Test-GLCanvas
-----------------------------------------------------------------*/
BEGIN_EVENT_TABLE(TSGLCanvas, wxGLCanvas)
EVT_SIZE(TSGLCanvas::OnSize)
EVT_ERASE_BACKGROUND(TSGLCanvas::OnEraseBackground)
EVT_TIMER(ID_TIMER,TSGLCanvas::OnTimer)
EVT_KEY_DOWN(TSGLCanvas::OnKeyDown)
EVT_KEY_UP(TSGLCanvas::OnKeyUp)
EVT_MOUSE_EVENTS(TSGLCanvas::OnMouseEvent)
END_EVENT_TABLE()
TSGLCanvas::TSGLCanvas(wxWindow *parent, wxWindowID id,
const wxPoint& pos, const wxSize& size, long style, const wxString& name)
: wxGLCanvas(parent, (wxGLCanvas*) NULL, id, pos, size, style|wxFULL_REPAINT_ON_RESIZE , name )
{
m_init = false;
//-
m_timer = new wxTimer(this, ID_TIMER);
m_timer->Start(1);
//-
}
TSGLCanvas::~TSGLCanvas()
{
}
void TSGLCanvas::OnTimer(wxTimerEvent& WXUNUSED(event))
{
Render();
}
void TSGLCanvas::OnKeyDown(wxKeyEvent& event)
{
switch ( event.GetKeyCode() )
{
case WXK_LEFT:
g_KeyPort = WXK_LEFT;
break;
case WXK_RIGHT:
g_KeyPort = WXK_RIGHT;
break;
case WXK_UP:
g_KeyPort = WXK_UP;
break;
case WXK_DOWN:
g_KeyPort = WXK_DOWN;
break;
case WXK_HOME:
g_KeyPort = WXK_HOME;
break;
case WXK_END:
g_KeyPort = WXK_END;
break;
case WXK_RETURN:
g_KeyPort = WXK_RETURN;
break;
}
}
void TSGLCanvas::OnKeyUp(wxKeyEvent& event)
{
g_KeyPort = 0;
}
void TSGLCanvas::OnMouseEvent(wxMouseEvent& event)
{
wxPoint pt(event.GetPosition());
g_MousePort.x = pt.x;
g_MousePort.y = pt.y;
g_MousePort.LeftUp = event.LeftUp();
g_MousePort.LeftDown = event.LeftDown();
g_MousePort.LeftDrag = event.Dragging();
}
void TSGLCanvas::InitGL()
{
TSGameInit();
}
void TSGLCanvas::Render()
{
#ifndef __WXMOTIF__
if (!GetContext()) return;
#endif
// Init OpenGL once, but after SetCurrent
if (!m_init)
{
m_init = true;
InitGL();
}
TSGameRun();
glFlush();
SwapBuffers();
}
//窗口大小改变
void TSGLCanvas::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
{
// [6/12/2009 Administrator]
SetCurrent();
//
glViewport(0, 0, (GLint) w, (GLint) h);
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
{
gluPerspective(45.0f,(GLfloat)w/(GLfloat)h, 0.1f ,5000.0f);
}
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
{
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearDepth(1.0f); // Depth Buffer Setup
//glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
glEnable(GL_COLOR_MATERIAL);
glLineWidth(2);
glClearColor( 0.350f, 0.530f, 0.701f, 1.0f );
}
}
}
//擦除背景
void TSGLCanvas::OnEraseBackground(wxEraseEvent& WXUNUSED(event))
{
// Do nothing, to avoid flashing.
}
/* -----------------------------------------------------------------------
Main Window
-------------------------------------------------------------------------*/
BEGIN_EVENT_TABLE(TSFrame, wxFrame)
EVT_MENU(wxID_EXIT, TSFrame::OnExit)
END_EVENT_TABLE()
//TSFrame构造
TSFrame::TSFrame(wxWindow *parent, const wxString& title, const wxPoint& pos,
const wxSize& size, long style)
: wxFrame(parent, wxID_ANY, title, pos, size, style)
{
m_canvas = NULL;
SetIcon(wxIcon(sample_xpm));
}
//TSFrame退出
void TSFrame::OnExit( wxCommandEvent& WXUNUSED(event) )
{
// true is to force the frame to close
Close(true);
}
//TSFrame创建窗口
TSFrame *TSFrame::Create()
{
wxString str = wxT("TSFrameWork with wxWidgets - OpenGL Version 1.0");
g_pFrame = new TSFrame(NULL, str, wxDefaultPosition,wxSize(800, 600));
g_pFrame->m_canvas = new TSGLCanvas(g_pFrame, wxID_ANY,wxDefaultPosition, wxSize(800, 600));
// Show the frame
g_pFrame->Show(true);
return g_pFrame;
}
/*------------------------------------------------------------------
Application object ( equivalent to main() )
------------------------------------------------------------------ */
IMPLEMENT_APP(TSApp)
bool TSApp::OnInit()
{
// Create the main frame window
(void) TSFrame::Create();
return true;
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
wxWidgets上渲染openGL(源码)wxWidgets上渲染openGL(源码)wxWidgets上渲染openGL(源码)wxWidgets上渲染openGL(源码)wxWidgets上渲染openGL(源码)wxWidgets上渲染openGL(源码)wxWidgets上渲染openGL(源码)
资源推荐
资源详情
资源评论
收起资源包目录
TSWXOpenGL框架.rar (16个子文件)
TSWX
TSGameMain.h 439B
TSMain.h 2KB
Debug
vc80.pdb 1.12MB
TSWX.exe.intermediate.manifest 726B
BuildLog.htm 4KB
TSWX.exe.embed.manifest.res 744B
mt.dep 67B
TSGameMain.obj 99KB
vc80.idb 1.47MB
TSWX.exe.embed.manifest 679B
sample.xpm 1KB
TSGameMain.cpp 227B
TSWX.vcproj 4KB
TSWX.vcproj.MICROSOF-13DEFF.Administrator.user 1KB
TSMain.cpp 5KB
TSHead.h 207B
共 16 条
- 1
资源评论
- hand91620122012-12-06下载下来了,但是运行不起来,提示有很多错误,不知道是什么原因
- dongpy2012-12-01没什么内容啊
Spiritring
- 粉丝: 155
- 资源: 39
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功