#include "include/raven.h" #include using namespace std; static int video_type=RAVEN_OPENGL; Core *core; Renderer *renderer; #if defined(WIN32)||defined(__WIN32__)||defined(_MSC_VER) #define OS_WIN32 #endif #ifdef OS_WIN32 void set_video_type() { if (MessageBox(NULL,"do you want to test direct3d9?", "RAVEN Direct3D Test",MB_YESNO|MB_ICONQUESTION)==IDYES) video_type=RAVEN_DIRECT3D9; } #endif void build_cube(VertexBuffer *buf); bool run=true,wireframe=false,showtext=true; bool cpress=false,tpress=false,wpress=false; int main(int argc,char *argv[]) { cout.sync_with_stdio(); /* this should pretty much ALWAYS be used in my opinion. It ensures that switching between printf and cout does NOT disrupt the stream. Since C/C++ are used together very often this is a must. */ #ifdef OS_WIN32 set_video_type(); #endif // set up the core factory CoreFactory::Singleton().Set("Test App",640,480,16,16,0); // create the system core. this has our video context and handles OS specific junk. if (!(core=CoreFactory::Singleton().Create(video_type))) { cerr<<"Failed to create system core!"<State(RAVEN_STATE_LIGHT|RAVEN_STATE_MATERIAL| RAVEN_STATE_TEXTURE|RAVEN_STATE_USE_HW_VERTEX_MEMORY,true); // load the stupid people image Pixelmap *image=PixelmapLoader::Singleton().LoadPixmap("stupidpplinternet.png"); if (!image) { cerr<<"Failed to load image!"<CreateTexture(image,SamplerState(8),0); if (!tex) { cerr<<"Failed to create texture!"<LoadFont("small.ttf",16); if (!font) { cerr<<"Failed to load font!"<CreateVertexBuffer(RAVEN_GEOMETRY_FLAG_INDICES| RAVEN_GEOMETRY_FLAG_VERTICES|RAVEN_GEOMETRY_FLAG_COLORS| RAVEN_GEOMETRY_FLAG_NORMALS|RAVEN_GEOMETRY_FLAG_TEXCOORDS); build_cube(cube); RenderTarget *rt=renderer->CreateRenderTargetColorTexture(SamplerState(4,RAVEN_MIPMAP_SAMPLE),8); if (!rt) { cerr<<"Failed to create render target!"<Blend(RAVEN_BLEND_ALPHA); renderer->SetCullMode(RAVEN_CULL_BACK); clock_t newtime=clock(),oldtime=newtime; float deltatime=0.0f; float ang=0.0f; while (run) { newtime=clock(); deltatime=(float)(newtime-oldtime)/(float)CLOCKS_PER_SEC; ang+=deltatime; oldtime=newtime; if (rt) { renderer->BindRenderTarget(rt); renderer->BeginScene(true,true,Vector4(Vector3(0.2f),1.0f)); // begin scene, clear color/depth { renderer->TargetViewport(Viewport(renderer->BoundRenderTarget())); renderer->PushProjection(); renderer->PushModelView(); renderer->LoadProjection(Projection( (float)(renderer->BoundRenderTarget()->GetWidth()/renderer->BoundRenderTarget()->GetHeight()), (float)PI/4.0f,1.0f,1024.0f)); renderer->State(RAVEN_STATE_LIGHT,false); renderer->LoadModelView(translate(Vector3(0.0f,0.0f,-4.0f))); renderer->MultModelView(rotateZXY(ang,ang,ang)); renderer->MultModelView(rotateZXY(0.0f,ang,0.0f)); renderer->State(RAVEN_STATE_WIREFRAME,wireframe); material.Tex(tex); material.UsingVertexColor(true); renderer->Material(material); renderer->RenderVertexBuffer(cube,RAVEN_GEOMETRY_TRIS); renderer->PopModelView(); renderer->PopProjection(); if (showtext) renderer->RenderText(font,5,5,"fonts work on both subsystems! YEY!"); } renderer->EndScene(false); // end scene, don't flip } renderer->BindRenderTarget(renderer->FrameBufferTarget()); renderer->BeginScene(true,true,Vector4(Vector3(0.2f),1.0f)); // begin scene, clear color/depth { renderer->TargetViewport(Viewport(renderer->BoundRenderTarget())); renderer->PushProjection(); renderer->PushModelView(); renderer->LoadProjection(Projection( (float)(renderer->BoundRenderTarget()->GetWidth()/renderer->BoundRenderTarget()->GetHeight()), (float)PI/4.0f,1.0f,1024.0f)); renderer->State(RAVEN_STATE_LIGHT,true); renderer->EnableLight(0,&light0); renderer->LoadModelView(translate(Vector3(0.0f,0.0f,-4.0f))); renderer->MultModelView(rotateZXY(ang,ang,ang)); renderer->MultModelView(rotateZXY(0.0f,ang,0.0f)); renderer->State(RAVEN_STATE_WIREFRAME,wireframe); Texture *tex2apply; if (rt) { rt->BindingMode(RAVEN_TEXTURE_BIND_TARGET); tex2apply=rt->GetTexture(); } else tex2apply=tex; material.Tex(tex2apply); material.UsingVertexColor(usevertcolor); renderer->Material(material); renderer->RenderVertexBuffer(cube,RAVEN_GEOMETRY_TRIS); renderer->DisableLight(0); renderer->PopModelView(); renderer->PopProjection(); if (showtext) renderer->RenderText(font,5,5,"fonts work on both subsystems! YEY!"); } renderer->EndScene(true); // end scene, don't flip if (renderer->GetCore()->KeyDown(RAVEN_KEY_ESCAPE)||renderer->GetCore()->IsAppTerm()) run=false; if (renderer->GetCore()->KeyDown(RAVEN_KEY_KEY_C)) cpress=true; else if (cpress) { cpress=false; usevertcolor=!usevertcolor; } if (renderer->GetCore()->KeyDown(RAVEN_KEY_KEY_T)) tpress=true; else if (tpress) { tpress=false; showtext=!showtext; } if (renderer->GetCore()->KeyDown(RAVEN_KEY_KEY_W)) wpress=true; else if (wpress) { wpress=false; wireframe=!wireframe; } } delete font; delete cube; delete image; delete tex; delete renderer; if (!core->Stop()) { cerr<<"Failed to stop system core!"<NumTextures(1); buf->NumVerts(24); buf->NumIndices(36); buf->Set(RAVEN_GEOMETRY_FLAG_INDICES,0,(void *)indices); buf->Set(RAVEN_GEOMETRY_FLAG_VERTICES,0,(void *)cubeverts); buf->Set(RAVEN_GEOMETRY_FLAG_NORMALS,0,(void *)cubenormals); buf->Set(RAVEN_GEOMETRY_FLAG_COLORS,0,(void *)cubecolors); buf->Set(RAVEN_GEOMETRY_FLAG_TEXCOORDS,0,(void *)cubetexcoords); }