/** * \brief Initialize font handler */ PUBLIC void Font_Init( void ) { W32 i; for( i = 0 ; i < MAX_FONTS ; ++i ) { myfonts[ i ] = NULL; } (void)createFont( "pics/font1.tga" ); (void)createFont( "pics/font2.tga" ); }
OSGTextNode::OSGTextNode(QObject *parent) : osgQtQuick::OSGNode(parent), h(new Hidden) { osg::ref_ptr<osgText::Font> textFont = createFont(QFont("Times")); h->text = createText(osg::Vec3(-100, 20, 0), "The osgQtQuick :-)\n" "И даже по русски!", 20.0f, textFont.get()); osg::ref_ptr<osg::Geode> textGeode = new osg::Geode(); h->text->setColor(osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f)); textGeode->addDrawable(h->text.get()); #if 0 h->text->setAutoRotateToScreen(true); setNode(textGeode.get()); #else osg::Camera *camera = createHUDCamera(-100, 100, -100, 100); camera->addChild(textGeode.get()); camera->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF); setNode(camera); #endif }
ossimFont* ossimFontFactoryRegistry::getDefaultFont()const { if(!theDefaultFont) { std::vector<ossimFontInformation> infoList; getFontInformationContainingFamilyName(infoList, "Times"); if(infoList.size() < 1) { getFontInformationContainingFamilyName(infoList, "Roman"); } if(infoList.size() < 1) { getFontInformationContainingFamilyName(infoList, "Sanz"); } if(infoList.size() < 1) { getFontInformation(infoList); } if(infoList.size()) { theDefaultFont = createFont(infoList[0]); theDefaultFont->setPixelSize(12, 12); } else { theDefaultFont = new ossimGdBitmapFont("gd sans", "bold", ossimGdSansBold); } } return theDefaultFont.get(); }
void FontResource::updateModelFromLogFont(const LOGFONT& logFont) { auto newFont = createFont (logFont); mFont->fontName (newFont->fontName()); mFont->size (newFont->size()); mFont->bold (newFont->bold()); mFont->italic (newFont->italic()); mFont->underline (newFont->underline()); }
/** * Font class for all games using F3D. */ Font::Font(GLuint charWidth, GLuint charHeight, const char *texName, GLboolean is_absPath) : m_texture(NULL), m_color(NULL) { createFont(charWidth, charHeight, charWidth, charHeight, texName, is_absPath); }
FTFontPtr FTGLFontDrawingObj::getFont(FTGLFontType fontType, bool bBold /*= false*/, bool bItalic /*= false*/ , bool bUnderLine /*= false*/, bool bStrikeout /*= false*/) { if ( !generateFontBufferFromDC(nullptr, bBold, bItalic, bUnderLine, bStrikeout) ) return nullptr; return createFont(fontType); }
void drawNumberOnTimeLabel(HDC hdc, RECT rect, LPCWSTR pWStr, COLORREF fontColor) { HFONT font = createFont(getRectHeight(rect) * 0.66 / 2); SetTextColor(hdc, fontColor); // Font color SetBkMode(hdc, TRANSPARENT); // Background color transparentk SelectObject(hdc, font); // Set font DrawText(hdc, pWStr, -1, &rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER); DeleteObject(font); }
//-------------------------------------------------------------- // create a font from "arial-10-b-i" style fontspec const mgFont* mgGenSurface::createFont( const char* spec) { // parse fontSpec mgString faceName; int size = 12; BOOL bold = false; BOOL italic = false; // parse fontSpec as facename-size-B-I mgString fontSpec(spec); int posn = fontSpec.find(0, "-"); if (posn < fontSpec.length()) { fontSpec.substring(faceName, 0, posn); posn = fontSpec.nextLetter(posn); } else faceName = fontSpec; mgString digits; if (posn < fontSpec.length()) { int dash2 = fontSpec.find(posn, "-"); if (dash2 != -1) { fontSpec.substring(digits, posn, dash2-posn); posn = dash2; } else { fontSpec.substring(digits, posn); posn = fontSpec.length(); } if (1 != sscanf((const char*) digits, "%d", &size)) throw new mgErrorMsg("2dBadFontSpec", "spec", "%s", (const char*) fontSpec); } char letter[MG_MAX_LETTER]; while (posn < fontSpec.length()) { posn = fontSpec.nextLetter(posn, letter); if (strcmp(letter, "-") != 0) throw new mgErrorMsg("2dBadFontSpec", "spec", "%s", (const char*) fontSpec); posn = fontSpec.nextLetter(posn, letter); if (_stricmp(letter, "B") == 0) bold = true; else if (_stricmp(letter, "I") == 0) italic = true; else throw new mgErrorMsg("2dBadFontSpec", "spec", "%s", (const char*) fontSpec); } return createFont(faceName, size, bold, italic); }
void drawNumberOnRect(HDC hdc, RECT rect, const int &number, COLORREF fontColor) { HFONT font = createFont(getRectHeight(rect) * 0.66); SetTextColor(hdc, fontColor); // Font color SetBkMode(hdc, TRANSPARENT); // Background color transparentk SelectObject(hdc, font); // Set font wchar_t buffer[256]; wsprintfW(buffer, L"%d", number); DrawText(hdc, buffer, -1, &rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER); DeleteObject(font); }
// on create/reset/lost/destroy bool fontNode::onCreateDevice(IDirect3DDevice9* pDevice) { onDestroyDevice(); m_pDevice = pDevice; if((m_pDevice)&&(m_strResname.GetLength() > 0)) { return createFont(); } return true; }
XImlib2Caption::XImlib2Caption(AbstractContainer * c, AbstractIcon * iParent, AbstractConfig * con, AbstractIconConfig * iConfig) : AbstractCaption(c, iParent, con, iConfig), XImlib2Image(c, iParent, con, iConfig), FONTSHIFT(4) { XDesktopContainer * xContainer = dynamic_cast<XDesktopContainer *>(AbstractImage::container); visual = imlib_context_get_visual(); cmap = imlib_context_get_colormap(); configure(); createFont(); }
GuiFont* FifechanManager::setDefaultFont(const std::string& path, uint32_t size, const std::string& glyphs) { m_fontpath = path; m_fontsize = size; m_fontglyphs = glyphs; m_defaultfont = createFont(); fcn::Widget::setGlobalFont(m_defaultfont); if (m_console) { m_console->reLayout(); } return m_defaultfont; }
PomodoroTimerApplication::PomodoroTimerApplication(int& argc, char** argv) : QApplication{argc, argv}, mIdleIcon{IdleIconPath}, mSystemTrayIcon{mIdleIcon}, mFont{createFont()}, mMinutesLeft{0}, mCurrentState{PomodoroState::Idle} { setupMenu(); mSystemTrayIcon.show(); mTimer.setInterval(IconUpdateIntervalMsec); connect(&mTimer, &QTimer::timeout, this, &PomodoroTimerApplication::onTimer); }
// 画数字 void drawNumberOnCell(HDC hdc, RECT cellRect, const int &number, COLORREF fontColor) { int fontSize = log2(number); double factor = fontSize < 7 ? 1 : (fontSize < 10 ? 1.5 : 2); HFONT font = createFont(getRectHeight(cellRect) * 0.66 / factor); SetTextColor(hdc, fontColor); // Font color SetBkMode(hdc, TRANSPARENT); // Background color transparentk SelectObject(hdc, font); // Set font wchar_t buffer[256]; wsprintfW(buffer, L"%d", number); DrawText(hdc, buffer, -1, &cellRect, DT_CENTER | DT_SINGLELINE | DT_VCENTER); DeleteObject(font); }
DocumentEditorPrivate(DocumentEditor* q) : m_debug(false) , m_border(true) , m_background(true) , q_ptr(q) , m_borderPen(QColor(0, 0, 0)) , m_font(createFont()) , m_fontMetrics(0) , m_undostack(new command::qt::UndoStackProxy(0)) , m_fs(new qt::system::FileSystem()) , m_document(new Document(m_fs, m_undostack)) , m_window() { m_window = m_document->register_listener(this); }
Interface::Interface(Framework* control) : fontlist(-1), framework(control), fps("0 FPS"), roundnum("Round 1"), paused(false), flashtimer(-1) { backTexture = framework->loadTexture("background2.bmp"); charTexture[0] = framework->loadTexture("q1.bmp"); charTexture[1] = framework->loadTexture("q2.bmp"); charTexture[2] = framework->loadTexture("q3.bmp"); charTexture[3] = framework->loadTexture("q4.bmp"); charTexture[4] = framework->loadTexture("q5.bmp"); // we need to have the textures at hand first createFont(); //for (int i = 32; i<128; i++) std::cout << (char)i << "\t"; }
void XeTeXFontMgr::getOpSizeRecAndStyleFlags(Font* theFont) { XeTeXFont font = createFont(theFont->fontRef, 655360); XeTeXFontInst* fontInst = (XeTeXFontInst*) font; if (font != 0) { const OpSizeRec* pSizeRec = getOpSize(font); if (pSizeRec != NULL) { theFont->opSizeInfo.designSize = pSizeRec->designSize; if (pSizeRec->subFamilyID == 0 && pSizeRec->nameCode == 0 && pSizeRec->minSize == 0 && pSizeRec->maxSize == 0) goto done_size; // feature is valid, but no 'size' range theFont->opSizeInfo.subFamilyID = pSizeRec->subFamilyID; theFont->opSizeInfo.nameCode = pSizeRec->nameCode; theFont->opSizeInfo.minSize = pSizeRec->minSize; theFont->opSizeInfo.maxSize = pSizeRec->maxSize; } done_size: const TT_OS2* os2Table = (TT_OS2*) fontInst->getFontTable(ft_sfnt_os2); if (os2Table != NULL) { theFont->weight = os2Table->usWeightClass; theFont->width = os2Table->usWidthClass; uint16_t sel = os2Table->fsSelection; theFont->isReg = (sel & (1 << 6)) != 0; theFont->isBold = (sel & (1 << 5)) != 0; theFont->isItalic = (sel & (1 << 0)) != 0; } const TT_Header* headTable = (TT_Header*) fontInst->getFontTable(ft_sfnt_head); if (headTable != NULL) { uint16_t ms = headTable->Mac_Style; if ((ms & (1 << 0)) != 0) theFont->isBold = true; if ((ms & (1 << 1)) != 0) theFont->isItalic = true; } const TT_Postscript* postTable = (const TT_Postscript*) fontInst->getFontTable(ft_sfnt_post); if (postTable != NULL) { theFont->slant = (int)(1000 * (tan(Fix2D(-postTable->italicAngle) * M_PI / 180.0))); } deleteFont(font); } }
void XeTeXFontMgr::getOpSizeRecAndStyleFlags(Font* theFont) { XeTeXFont font = createFont(theFont->fontRef, 655360); if (font != 0) { const OpSizeRec* pSizeRec = getOpSizePtr(font); if (pSizeRec != NULL) { theFont->opSizeInfo.designSize = SWAP(pSizeRec->designSize); if (SWAP(pSizeRec->subFamilyID) == 0 && SWAP(pSizeRec->nameCode) == 0 && SWAP(pSizeRec->minSize) == 0 && SWAP(pSizeRec->maxSize) == 0) goto done_size; // feature is valid, but no 'size' range theFont->opSizeInfo.subFamilyID = SWAP(pSizeRec->subFamilyID); theFont->opSizeInfo.nameCode = SWAP(pSizeRec->nameCode); theFont->opSizeInfo.minSize = SWAP(pSizeRec->minSize); theFont->opSizeInfo.maxSize = SWAP(pSizeRec->maxSize); } done_size: const OS2TableHeader* os2Table = (const OS2TableHeader*)getFontTablePtr(font, LE_OS_2_TABLE_TAG); if (os2Table != NULL) { theFont->weight = SWAP(os2Table->usWeightClass); theFont->width = SWAP(os2Table->usWidthClass); UInt16 sel = SWAP(os2Table->fsSelection); theFont->isReg = (sel & (1 << 6)) != 0; theFont->isBold = (sel & (1 << 5)) != 0; theFont->isItalic = (sel & (1 << 0)) != 0; } const HEADTable* headTable = (const HEADTable*)getFontTablePtr(font, LE_HEAD_TABLE_TAG); if (headTable != NULL) { UInt16 ms = SWAP(headTable->macStyle); if ((ms & (1 << 0)) != 0) theFont->isBold = true; if ((ms & (1 << 1)) != 0) theFont->isItalic = true; } const POSTTable* postTable = (const POSTTable*)getFontTablePtr(font, LE_POST_TABLE_TAG); if (postTable != NULL) { theFont->slant = (int)(1000 * (tan(Fix2X(-SWAP(postTable->italicAngle)) * M_PI / 180.0))); } deleteFont(font); } }
void RoutingDrawWidget::drawContents(QPainter* p, int cx, int cy, int cw, int ch) { RoutingWidget *parent = (RoutingWidget *)parentWidget(); StrGlobal *structure = parent->getStructure(); if (!structure) return; RSItemBaseWithType *item; DrawingParams dp(parent->getZoomLevel(), this->viewport(), NULL, p); p->setFont(createFont(parent->getZoomLevel())); for(item = structure->UsedItems.first(); item; item = structure->UsedItems.next() ) { if (item->flagNew() || item->flagChanged()) { item->calcSize(); item->setFlagNew(false); item->setFlagChanged(false); } item->draw(&dp); } // if in link mode if (mode == DragLink) { QPainter p(this->viewport()); int piox, pioy; int ex = selectEndPoint.x(); int ey = selectEndPoint.y(); ((StrPatch *)linkStart->getOwner())->getIOPoint(linkStart, &piox, &pioy); contentsToViewport(parent->zoomVal(piox), parent->zoomVal(pioy), piox, pioy); contentsToViewport(parent->zoomVal(ex), parent->zoomVal(ey), ex, ey); p.setPen(LINE_PEN); p.drawLine(QPoint(piox, pioy), QPoint(ex, ey)); p.setPen(DEF_PAINTING_PEN); } }
//-------------------------------------------------------------- // create a font from "arial-10-b-i" style fontspec const mgFont* mgXPSurface::createFont( const char* fontSpec) { // parse fontSpec char faceName[_MAX_PATH]; int size = 12; BOOL bold = false; BOOL italic = false; // parse fontSpec as facename-size-B-I int len = (int) strcspn(fontSpec, "-"); memcpy(faceName, fontSpec, len); faceName[len] = '\0'; fontSpec += len; if (fontSpec[0] == '-') { fontSpec++; char sizeStr[10]; len = (int) strcspn(fontSpec, "-"); len = min(sizeof(sizeStr)-1, len); memcpy(sizeStr, fontSpec, len); sizeStr[len] = '\0'; size = atoi(sizeStr); fontSpec += len; } while (fontSpec[0] == '-') { fontSpec++; len = (int) strcspn(fontSpec, "-"); if (toupper(fontSpec[0]) == 'B') bold = true; else if (toupper(fontSpec[0]) == 'I') italic = true; fontSpec += len; } return createFont(faceName, size, bold, italic); }
int main() { // creates a window and GLES context if (makeContext() != 0) exit(-1); // all the shaders have at least texture unit 0 active so // activate it now and leave it active glActiveTexture(GL_TEXTURE0); flareTex = loadPNG("resources/textures/cloud.png"); width = getDisplayWidth(); height = getDisplayHeight(); glViewport(0, 0, getDisplayWidth(), getDisplayHeight()); // initialises glprint's matrix, shader and texture initGlPrint(getDisplayWidth(), getDisplayHeight()); font1=createFont("resources/textures/font.png",0,256,16,16,16); initSprite(getDisplayWidth(), getDisplayHeight()); fileid = 0; loadfile(); for (int i=0; i<max_flares; i++) { flares[i].x=rand_range(0,getDisplayWidth()); flares[i].y=rand_range(0,getDisplayHeight()); flares[i].vx=rand_range(0,10)-5; flares[i].vy=rand_range(0,10)-5; } /*for (int i=0; i<max_targets; i++) { targets[i].x=rand_range(0,getDisplayWidth()); targets[i].y=rand_range(0,getDisplayHeight()); targets[i].flares = 0; }*/ /*for (int i=0; i<max_flares; i++) { flares[i].x=rand_range(0,getDisplayWidth()); flares[i].y=rand_range(0,getDisplayHeight()); flares[i].vx=rand_range(0,10)-5; flares[i].vy=rand_range(0,10)-5; flares[i].target = (int)rand_range(0,max_targets); targets[flares[i].target].flares ++; }*/ // we don't want to draw the back of triangles // the blending is set up for glprint but disabled // while not in use glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glDisable(GL_DEPTH_TEST); glClearColor(0, 0.5, 1, 1); // count each frame int num_frames = 0; // set to true to leave main loop bool quit = false; // get a pointer to the key down array keys = getKeys(); int* mouse = getMouse(); while (!quit) { // the main loop doEvents(); // update mouse and key arrays if (keys[KEY_ESC]) quit = true; // exit if escape key pressed if (keys[KEY_SPACE]) relocate_targets(); // exit if escape key pressed if (keys[KEY_RETURN]) reassign_flares(); // exit if escape key pressed if (keys[KEY_S] && !lastkeys[KEY_S]) save(); // exit if escape key pressed if (keys[KEY_CURSL] && !lastkeys[KEY_CURSL]){ fileid--; if (fileid <0) fileid = 0; loadfile(); // exit if escape key pressed } if (keys[KEY_CURSR] && !lastkeys[KEY_CURSR]){ fileid++; loadfile(); // exit if escape key pressed } if (keys[KEY_C]){ max_targets = 1; // exit if escape key pressed reassign_flares(); } lastkeys[KEY_S] = keys[KEY_S]; lastkeys[KEY_CURSL] = keys[KEY_CURSL]; lastkeys[KEY_CURSR] = keys[KEY_CURSR]; mx = mouse[0]; my = mouse[1]; if(mouse[2] != 0){ spawn_target(mx,my); } for (int i=0; i<RE_MULTIPLY; i++){ random_events(); } think(); render(); // the render loop usleep(1600); // no need to run cpu/gpu full tilt } closeContext(); // tidy up return 0; }
bool ARX_Text_Init() { res::path file; if(!getFontFile(file)) { return false; } res::path debugFontFile = "misc/dejavusansmono.ttf"; float scale = std::max(std::min(g_sizeRatio.y, g_sizeRatio.x), .001f); if(scale == created_font_scale) { return true; } created_font_scale = scale; // Keep small font small when increasing resolution // TODO font size jumps around scale = 1 float small_scale = scale > 1.0f ? scale * 0.8f : scale; delete pTextManage; pTextManage = new TextManager(); delete pTextManageFlyingOver; pTextManageFlyingOver = new TextManager(); FontCache::initialize(); Font * nFontMainMenu = createFont(file, "system_font_mainmenu_size", 58, scale); Font * nFontMenu = createFont(file, "system_font_menu_size", 32, scale); Font * nFontControls = createFont(file, "system_font_menucontrols_size", 22, scale); Font * nFontCredits = createFont(file, "system_font_menucredits_size", 36, scale); Font * nFontInGame = createFont(file, "system_font_book_size", 18, small_scale); Font * nFontInGameNote = createFont(file, "system_font_note_size", 18, small_scale); Font * nFontInBook = createFont(file, "system_font_book_size", 18, small_scale); Font * nFontDebug = FontCache::getFont(debugFontFile, 14); // Only release old fonts after creating new ones to allow same fonts to be cached. FontCache::releaseFont(hFontMainMenu); FontCache::releaseFont(hFontMenu); FontCache::releaseFont(hFontControls); FontCache::releaseFont(hFontCredits); FontCache::releaseFont(hFontInGame); FontCache::releaseFont(hFontInGameNote); FontCache::releaseFont(hFontInBook); FontCache::releaseFont(hFontDebug); hFontMainMenu = nFontMainMenu; hFontMenu = nFontMenu; hFontControls = nFontControls; hFontCredits = nFontCredits; hFontInGame = nFontInGame; hFontInGameNote = nFontInGameNote; hFontInBook = nFontInBook; hFontDebug = nFontDebug; if(!hFontMainMenu || !hFontMenu || !hFontControls || !hFontCredits || !hFontInGame || !hFontInGameNote || !hFontInBook ) { LogCritical << "Could not load font " << file << " for scale " << scale << " / small scale " << small_scale; return false; } if(!hFontDebug) { LogCritical << "Could not load font " << debugFontFile; return false; } LogInfo << "Loaded font " << file << " with sizes " << hFontMainMenu->getSize() << ", " << hFontMenu->getSize() << ", " << hFontControls->getSize() << ", " << hFontCredits->getSize() << ", " << hFontInGame->getSize() << ", " << hFontInGameNote->getSize() << ", " << hFontInBook->getSize() << ", " << hFontDebug->getSize(); return true; }
int main() { lightDir.x=0.5; lightDir.y=.7; lightDir.z=-0.5; kmVec3Normalize(&lightDir,&lightDir); // creates a window and GLES context if (makeContext() != 0) exit(-1); // all the shaders have at least texture unit 0 active so // activate it now and leave it active glActiveTexture(GL_TEXTURE0); // The obj shapes and their textures are loaded cubeTex = loadPNG("resources/textures/dice.png"); loadObj(&cubeObj, "resources/models/cube.gbo", "resources/shaders/textured.vert", "resources/shaders/textured.frag"); shipTex = loadPNG("resources/textures/shipv2.png"); loadObjCopyShader(&shipObj,"resources/models/ship.gbo",&cubeObj); alienTex = loadPNG("resources/textures/alien.png"); loadObjCopyShader(&alienObj, "resources/models/alien.gbo", &cubeObj); shotTex = loadPNG("resources/textures/shot.png"); loadObjCopyShader(&shotObj, "resources/models/shot.gbo", &cubeObj); expTex = loadPNG("resources/textures/explosion.png"); playerPos.x = 0; playerPos.y = 0; playerPos.z = 0; kmMat4Identity(&view); pEye.x = 0; pEye.y = 2; pEye.z = 4; pCenter.x = 0; pCenter.y = 0; pCenter.z = -5; pUp.x = 0; pUp.y = 1; pUp.z = 0; kmMat4LookAt(&view, &pEye, &pCenter, &pUp); // projection matrix, as distance increases // the way the model is drawn is effected kmMat4Identity(&projection); kmMat4PerspectiveProjection(&projection, 45, (float)getDisplayWidth() / getDisplayHeight(), 0.1, 100); glViewport(0, 0, getDisplayWidth(), getDisplayHeight()); // these two matrices are pre combined for use with each model render kmMat4Assign(&vp, &projection); kmMat4Multiply(&vp, &vp, &view); // initialises glprint's matrix shader and texture initGlPrint(getDisplayWidth(), getDisplayHeight()); font1=createFont("resources/textures/font.png",0,256,16,16,16); font2=createFont("resources/textures/bigfont.png",32,512,9.5,32,48); glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_BLEND); // only used by glprintf glEnable(GL_DEPTH_TEST); struct timeval t, ta, t1, t2; // fps stuff gettimeofday(&t1, NULL); int num_frames = 0; bool quit = false; mouse = getMouse(); keys = getKeys(); resetAliens(); for (int n = 0; n < MAX_PLAYER_SHOTS; n++) { playerShots[n].alive = false; } initPointClouds("resources/shaders/particle.vert", "resources/shaders/particle.frag",(float)getDisplayWidth()/24.0); for (int n = 0; n < MAX_ALIENS; n++) { aliens[n].explosion=createPointCloud(40); resetExposion(aliens[n].explosion); // sets initials positions } while (!quit) { // the main loop doEvents(); // update mouse and key arrays // mask of 4 is right mouse if (keys[KEY_ESC]) quit = true; glClearColor(0, .5, 1, 1); // render between two gettimeofday calls so // we can sleep long enough to roughly sync // to ~60fps but not on the pi! // TODO find something a tad more elegent long i; gettimeofday(&t, NULL); i = t.tv_sec * 1e6 + t.tv_usec; // render(); float rad; // radians rotation based on frame counter glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); frame++; rad = frame * (0.0175f * 2); kmMat4Identity(&model); kmMat4Translation(&model, playerPos.x, playerPos.y, playerPos.z); playerCroll += (PIDcal(playerRoll, playerCroll, &playerPre_error, &playerIntegral) / 2); kmMat4RotationPitchYawRoll(&model, 0, 3.1416, playerCroll * 3); // kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); kmMat4Assign(&mv, &view); kmMat4Multiply(&mv, &mv, &model); glBindTexture(GL_TEXTURE_2D, shipTex); drawObj(&shipObj, &mvp, &mv, lightDir, viewDir); glPrintf(50 + sinf(rad) * 16, 240 + cosf(rad) * 16, font2,"frame=%i fps=%3.2f", frame, lfps); kmVec3 tmp; playerFireCount--; if (keys[KEY_LCTRL] && playerFireCount < 0) { struct playerShot_t *freeShot; freeShot = getFreeShot(); if (freeShot != 0) { playerFireCount = 15; freeShot->alive = true; kmVec3Assign(&freeShot->pos, &playerPos); } } for (int n = 0; n < MAX_PLAYER_SHOTS; n++) { if (playerShots[n].alive) { playerShots[n].pos.z -= .08; if (playerShots[n].pos.z < -10) playerShots[n].alive = false; kmMat4Identity(&model); kmMat4Translation(&model, playerShots[n].pos.x, playerShots[n].pos.y, playerShots[n].pos.z); kmMat4RotationPitchYawRoll(&model, rad * 4, 0, -rad * 4); kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); kmMat4Assign(&mv, &view); kmMat4Multiply(&mv, &mv, &model); glBindTexture(GL_TEXTURE_2D, shotTex); drawObj(&shotObj, &mvp, &mv, lightDir, viewDir); } } playerRoll = 0; if (keys[KEY_CURSL] && playerPos.x > -10) { playerPos.x -= 0.1; playerRoll = .2; } if (keys[KEY_CURSR] && playerPos.x < 10) { playerPos.x += 0.1; playerRoll = -.2; } pEye.x = playerPos.x * 1.25; pCenter.x = playerPos.x; pCenter.y = playerPos.y + 1; pCenter.z = playerPos.z; int deadAliens; deadAliens = 0; for (int n = 0; n < MAX_ALIENS; n++) { if (aliens[n].alive == true) { kmMat4Identity(&model); kmMat4Translation(&model, aliens[n].pos.x, aliens[n].pos.y, aliens[n].pos.z); kmMat4RotationPitchYawRoll(&model, -.4, 0, 0); kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); kmMat4Assign(&mv, &view); kmMat4Multiply(&mv, &mv, &model); glBindTexture(GL_TEXTURE_2D, alienTex); drawObj(&alienObj, &mvp, &mv, lightDir, viewDir); kmVec3 d; for (int i = 0; i < MAX_PLAYER_SHOTS; i++) { kmVec3Subtract(&d, &aliens[n].pos, &playerShots[i].pos); if (kmVec3Length(&d) < .7 && playerShots[i].alive) { aliens[n].alive = false; playerShots[i].alive = false; aliens[n].exploding = true; resetExposion(aliens[n].explosion); } } } if (aliens[n].alive != true && aliens[n].exploding != true) { deadAliens++; } } if (deadAliens == MAX_ALIENS) { resetAliens(); } // draw explosions after ALL aliens for (int n = 0; n < MAX_ALIENS; n++) { if (aliens[n].exploding==true) { kmMat4Identity(&model); kmMat4Translation(&model, aliens[n].pos.x, aliens[n].pos.y, aliens[n].pos.z); kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); glBindTexture(GL_TEXTURE_2D, expTex); drawPointCloud(aliens[n].explosion, &mvp); aliens[n].explosion->tick=aliens[n].explosion->tick+0.05; if (aliens[n].explosion->tick>1.25) { aliens[n].exploding=false; } else { // update the explosion for (int i=0; i<aliens[n].explosion->totalPoints; i++) { float t; t=aliens[n].explosion->tick; if (i>aliens[n].explosion->totalPoints/2) t=t/2.0; aliens[n].explosion->pos[i*3]=aliens[n].explosion->vel[i*3] * t; aliens[n].explosion->pos[i*3+1]=aliens[n].explosion->vel[i*3+1] * t; aliens[n].explosion->pos[i*3+2]=aliens[n].explosion->vel[i*3+2] * t; } } } } // move camera kmMat4LookAt(&view, &pEye, &pCenter, &pUp); kmMat4Assign(&vp, &projection); kmMat4Multiply(&vp, &vp, &view); kmVec3Subtract(&viewDir,&pEye,&pCenter); kmVec3Normalize(&viewDir,&viewDir); // dump values glPrintf(100, 280, font1,"eye %3.2f %3.2f %3.2f ", pEye.x, pEye.y, pEye.z); glPrintf(100, 296, font1,"centre %3.2f %3.2f %3.2f ", pCenter.x, pCenter.y, pCenter.z); glPrintf(100, 320, font1,"mouse %i,%i %i ", mouse[0], mouse[1], mouse[2]); glPrintf(100, 340, font1,"frame %i %i ", frame, frame % 20); swapBuffers(); gettimeofday(&ta, NULL); long j = (ta.tv_sec * 1e6 + ta.tv_usec); i = j - i; if (i < 0) i = 1000000; // pass through - slower that 60fps if (i < 16000) usleep(16000 - i); // every 10 frames average the time taken and store // fps value for later printing with glprintf if (++num_frames % 10 == 0) { gettimeofday(&t2, NULL); float dtf = t2.tv_sec - t1.tv_sec + (t2.tv_usec - t1.tv_usec) * 1e-6; lfps = num_frames / dtf; num_frames = 0; t1 = t2; } } closeContext(); return 0; }
// OpenGL display initilization bool COpenGlDisplay::myInit(CWnd *wnd) { // 初始化转换值 shiftKeyStatus = FALSE; robotScale = 0.5; robotHeight = 0.2; xRot = -90.f; yRot = 10.f; zRot = yRot; xTrans = 0.f; yTrans = -2.f; zTrans = -8.f; vs.eyex = 1.0; vs.eyey = 3.5; vs.eyez = -6; vs.centerx = xTrans; vs.centery = yTrans; vs.centerz = zTrans; vs.upx = 0; vs.upy = 1; vs.upz = 0; // ============需要按实际情况设定======= // CRect mRect; hrenderDC=::GetDC(wnd->m_hWnd); if(setWindowPixelFormat(hrenderDC)==FALSE) //设置像素格式 return 0; if(createViewGLContext(hrenderDC)==FALSE) // 取得着色描述表 return 0; wnd->GetClientRect(&mRect); glViewport(0,0,mRect.Width(),mRect.Height()); glMatrixMode(GL_PROJECTION); // 选择投影矩阵 glLoadIdentity(); // 重置投影矩阵 gluPerspective(90,1.0,0.01,100.0); // 设置视口的大小 glMatrixMode(GL_MODELVIEW); // 选择模型观察矩阵 glLoadIdentity(); // 重置模型观察矩阵 // ============需要按实际情况设定======= // gluLookAt(vs.eyex, vs.eyey, vs.eyez, vs.centerx, vs.centery, vs.centerz, vs.upx, vs.upy, vs.upz); // 调整观察, // ============需要按实际情况设定======= // glShadeModel(GL_SMOOTH); // Enable Smooth Shading glClearColor(200.0/255.0, 200.0/255.0, 200.0/255.0, 0); // Black Background glClearDepth(1.0f); // Depth Buffer Setup glEnable(GL_DEPTH_TEST); // Enables Depth Testing glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); createFont(); GLfloat lightPos[] ={0, 0, 0}; GLfloat ambientLight[] = {0.3f, 0.3f, 0.3f, 1.0f}; GLfloat diffuseLight[] = {0.5f, 0.5f, 0.5f, 1.0f}; //glEnable(GL_LIGHTING); glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight); //设置并启动光照 glLightfv(GL_LIGHT0, GL_POSITION, lightPos); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); //设置材料属性,与glColor值对应 glEnable(GL_COLOR_MATERIAL); //启动颜色跟踪 this->buildRobotList(); // construct the show list this->buildWorldFrameList(); this->buildGroundList(); return true; }
// --------------------------------------------------------------------------- int main(int argc, char* argv[]) { signal(SIGINT, (sig_t)cleanup); // load settings file char* settings_file = NULL; int settings = 0; if(argc == 2) { settings_file = argv[1]; settings = Settings_Load(argv[1]); } if(!settings) { settings_file = "default.conf"; if(!Settings_Load("default.conf")) { printf("%s\r\n", _lng(ERROR_LOADING_SETTINGS)); return 0; } } // load settings FW_VERSION = Settings_Get("gui", "version"); SONG_FILE = Settings_Get("files", "song"); CURRENT_STATION_FILE = Settings_Get("files", "current_station"); STATIONS_FILE = Settings_Get("files", "stations"); USB_PATH = Settings_Get("files", "usb"); // check for running instance char* single_instance_cmd = Settings_Get("programs", "check_running"); ignore_result(system(single_instance_cmd)); FILE *running = fopen("fw.running", "r"); if(running == NULL) { printf("Cannot check if firmware is running, aborting.\r\n"); exit(0); } if(fgetc(running) >= '2') { fclose(running); printf("Firmware is already running!\r\nExiting...\r\n"); exit(0); } else { fclose(running); } if(strcmp(Settings_Get("hardware", "io"), "sim") == 0) IO_SetSimulate(1); if(strcmp(Settings_Get("hardware", "lcd"), "sim") == 0) GLCDD_SetSimulate(1); else if(strcmp(Settings_Get("hardware", "lcd"), "bmp") == 0) GLCDD_SetSimulate(2); GLCDD_Init(); IO_Init(); Language_Init(Settings_Get("gui", "language")); Screen_Init(silkscreen_8); Screen screen = SCREEN_MAIN; // create fonts fnt_dejavu_9 = createFont(dejavu_9); fnt_dejavu_9b = createFont(dejavu_9_b); fnt_silkscreen_8 = createFont(silkscreen_8); // register screens Screen_Add(SCREEN_MAIN, init_Main, draw_Main, exit_Main); Screen_Add(SCREEN_NOW_PLAYING, init_NowPlaying, draw_NowPlaying, exit_NowPlaying); Screen_Add(SCREEN_STATIONS, init_Stations, draw_Stations, exit_Stations); Screen_Add(SCREEN_INFO, NULL, draw_Info, NULL); Screen_Add(SCREEN_USB, init_USB, draw_USB, NULL); Screen_Add(SCREEN_SHUTDOWN, init_Shutdown, draw_Shutdown, NULL); Screen_Add(SCREEN_SETTINGS, init_Settings, draw_Settings, exit_Settings); Screen_Add(SCREEN_WIFI_SCAN, init_WifiScan, draw_WifiScan, exit_WifiScan); Screen_Add(SCREEN_WIFI_AUTH, init_WifiAuth, draw_WifiAuth, NULL); Screen_Add(SCREEN_WIFI_CONNECT, init_WifiConnect, draw_WifiConnect, NULL); Screen_Add(SCREEN_LANGUAGE, init_Language, draw_Language, exit_Language); Screen_Add(SCREEN_VOLUME, init_Volume, draw_Volume, NULL); Screen_Add(SCREEN_SHOUTCAST, init_Shoutcast, draw_Shoutcast, exit_Shoutcast); Screen_Add(SCREEN_SHOUTCAST_LIST, init_ShoutcastList, draw_ShoutcastList, exit_ShoutcastList); Screen_Add(SCREEN_SHOUTCAST_GENRE, init_ShoutcastGenre, draw_ShoutcastGenre, exit_ShoutcastGenre); Screen_Add(SCREEN_SHOUTCAST_SEARCH, init_ShoutcastSearch, draw_ShoutcastSearch, NULL); Screen_Add(SCREEN_MANAGE_STATION, init_ManageStation, draw_ManageStation, exit_ManageStation); Screen_Add(SCREEN_SNOOZE, init_Snooze, draw_Snooze, exit_Snooze); Screen_Add(SCREEN_TIMEOUT, init_Timeout, draw_Timeout, NULL); Screen_SetRefreshTimeout(SCREEN_INFO, 2); Screen_SetRefreshTimeout(SCREEN_MAIN, 10); Screen_SetRefreshTimeout(SCREEN_NOW_PLAYING, 1); Screen_SetRefreshTimeout(SCREEN_STATIONS, 10); Screen_SetRefreshTimeout(SCREEN_USB, 1); Screen_SetRefreshTimeout(SCREEN_SHUTDOWN, 10); Screen_SetRefreshTimeout(SCREEN_WIFI_SCAN, 1); Screen_SetRefreshTimeout(SCREEN_WIFI_AUTH, 10); Screen_SetRefreshTimeout(SCREEN_WIFI_CONNECT, 1); Screen_SetRefreshTimeout(SCREEN_LANGUAGE, 10); Screen_SetRefreshTimeout(SCREEN_VOLUME, 10); Screen_SetRefreshTimeout(SCREEN_SHOUTCAST, 10); Screen_SetRefreshTimeout(SCREEN_SHOUTCAST_LIST, 10); Screen_SetRefreshTimeout(SCREEN_SHOUTCAST_GENRE, 10); Screen_SetRefreshTimeout(SCREEN_SHOUTCAST_SEARCH, 10); Screen_SetRefreshTimeout(SCREEN_MANAGE_STATION, 10); Screen_SetRefreshTimeout(SCREEN_SNOOZE, 10); Screen_SetRefreshTimeout(SCREEN_TIMEOUT, 10); Screen_ShowLoadingScreen(SCREEN_USB, 1); Screen_ShowLoadingScreen(SCREEN_VOLUME, 1); Screen_ShowLoadingScreen(SCREEN_SHOUTCAST_LIST, 1); Screen_ShowLoadingScreen(SCREEN_SHOUTCAST_GENRE, 1); // reset song info resetMetaInfo(); // start ui Screen_Goto(SCREEN_MAIN); // background light GLCDD_BacklightTimeout(atoi(Settings_Get("hardware", "timeout"))); int keep_light_when_playing = 0; if(strcmp(Settings_Get("gui", "keep_light_when_playing"), "true") == 0) keep_light_when_playing = 1; GLCDD_BacklightReset(); uint64_t last_io = 0; while(1) { #ifndef SIMULATE if(getTimeMillisecond() - last_io >= 25) { IO_Get(); last_io = getTimeMillisecond(); } #else IO_Get(); #endif if(IO_HasChanged()) { Screen_ForceRedraw(); GLCDD_BacklightReset(); } screen = Screen_GetActive(); // --------------------------------------------------------------------------- if(screen == SCREEN_MAIN) { int selection = Menu_IsChosen(menu_main); if(selection == 0) { // goto now playing screen Screen_Goto(SCREEN_NOW_PLAYING); } else if(selection == 1) { // goto stations screen Screen_Goto(SCREEN_STATIONS); } else if(selection == 2) { // goto shoutcast browser Screen_Goto(SCREEN_SHOUTCAST); } else if(selection == 3) { // goto usb screen Screen_Goto(SCREEN_USB); } else if(selection == 4) { // goto info screen Screen_Goto(SCREEN_SETTINGS); } } // --------------------------------------------------------------------------- else if(screen == SCREEN_INFO) { if(IO_GetButton(0)) { Screen_Goto(SCREEN_SETTINGS); } } // --------------------------------------------------------------------------- else if(screen == SCREEN_STATIONS) { int selection = Menu_IsChosen(menu_stations); if(selection != -1) { // start station playStation(Menu_GetItemTag(menu_stations, selection)); } // add station as favorite if(IO_GetButtonLong(3)) asFavorite(1); if(IO_GetButtonLong(4)) asFavorite(2); if(IO_GetButtonLong(5)) asFavorite(3); if(IO_GetButtonLong(6)) asFavorite(4); } // --------------------------------------------------------------------------- else if(screen == SCREEN_NOW_PLAYING) { // if at now playing screen, backlight is always on if(keep_light_when_playing) GLCDD_BacklightReset(); } // --------------------------------------------------------------------------- else if(screen == SCREEN_SETTINGS) { int selection = Menu_IsChosen(menu_settings); if(selection == 0) { // goto info screen Screen_Goto(SCREEN_INFO); } else if(selection == 1) { // goto wifi scanning screen Screen_Goto(SCREEN_WIFI_SCAN); } else if(selection == 2) { // goto language selection Screen_Goto(SCREEN_LANGUAGE); } else if(selection == 3) { // goto volume adjustment Screen_Goto(SCREEN_VOLUME); } else if(selection == 4) { // goto backlight timeout Screen_Goto(SCREEN_TIMEOUT); } else if(selection == 5) { // goto station manager Screen_Goto(SCREEN_MANAGE_STATION); } else if(selection == 6) { // restart firmware // stop all music stopMusic(); // kill all streams ignore_result(system(Settings_Get("programs", "killall"))); // restart self execv(argv[0], argv); } else if(selection == 7) { // shutdown Screen_Goto(SCREEN_SHUTDOWN); } } // --------------------------------------------------------------------------- else if(screen == SCREEN_WIFI_SCAN) { int selection = Menu_IsChosen(menu_wifi_scan); if(selection != -1) { // save ssid Settings_Add("wifi", "ssid", Menu_GetItemText(menu_wifi_scan, selection)); // go to authentification Screen_Goto(SCREEN_WIFI_AUTH); } } // --------------------------------------------------------------------------- else if(screen == SCREEN_WIFI_AUTH) { if(Keyboard_IsConfirmed()) { // connect to wifi network Settings_Add("wifi", "pwd", Keyboard_GetText()); printf("Connecting to '%s' with key '%s'\r\n", Settings_Get("wifi", "ssid"), Settings_Get("wifi", "pwd")); Screen_Goto(SCREEN_WIFI_CONNECT); } } // --------------------------------------------------------------------------- else if(screen == SCREEN_LANGUAGE) { // change language int selection = Menu_IsChosen(menu_language); if(selection != -1) { char disp[64]; int i; strcpy(disp, Menu_GetItemText(menu_language, selection)); for(i = strlen(disp) - 1; i >= 0; i--) { if(disp[i] == ')') disp[i] = 0; if(disp[i] == '(') { i++; break; } } Settings_Add("gui", "language", &disp[i]); Language_Cleanup(); Language_Init(&disp[i]); Settings_Save(settings_file); Screen_Goto(SCREEN_SETTINGS); } } // --------------------------------------------------------------------------- else if(screen == SCREEN_VOLUME) { if(IO_GetButton(0)) { // go back to settings Screen_Goto(SCREEN_SETTINGS); } } // --------------------------------------------------------------------------- else if(screen == SCREEN_SHOUTCAST) { int selection = Menu_IsChosen(menu_shoutcast); if(selection == 0) { // go to shoutcast top stations setShoutcastListUrl(Settings_Get("shoutcast", "list_url")); printf("'%s'\r\n", Settings_Get("shoutcast", "list_url")); setStationsParentGenre("X"); setCurrentGenre(" "); Screen_Goto(SCREEN_SHOUTCAST_LIST); } else if(selection == 1) { // random station setShoutcastListUrl(Settings_Get("shoutcast", "random_url")); setStationsParentGenre("X"); setCurrentGenre(" "); Screen_Goto(SCREEN_SHOUTCAST_LIST); } else if(selection == 2) { // go to genre list setShoutcastGenreParent("0"); Screen_Goto(SCREEN_SHOUTCAST_GENRE); } else if(selection == 3) { // go to station search Screen_Goto(SCREEN_SHOUTCAST_SEARCH); } } // --------------------------------------------------------------------------- else if(screen == SCREEN_SHOUTCAST_GENRE) { int selection = Menu_IsChosen(menu_genres); if(selection != -1) { if(selection == 0) { // back if(strcmp(getShoutcastGenreParent(), "0") == 0) { // main genres Screen_Goto(SCREEN_SHOUTCAST); } else { // sub genre -> go back to main genres setShoutcastGenreParent("0"); Screen_Goto(SCREEN_SHOUTCAST_GENRE); } } else { // list stations or sub genre ShoutcastGenre* info = getChosenGenre((int)Menu_GetItemTag(menu_genres, selection)); // show sub genres if(info->has_children) { setStationsParentGenre(info->id); setShoutcastGenreParent(info->id); Screen_Goto(SCREEN_SHOUTCAST_GENRE); } else { // show stations char buffer[128]; sprintf(buffer, Settings_Get("shoutcast", "stations_by_genre_url"), info->name); setShoutcastListUrl(buffer); setCurrentGenre(info->name); Screen_Goto(SCREEN_SHOUTCAST_LIST); } } } } // --------------------------------------------------------------------------- else if(screen == SCREEN_SHOUTCAST_LIST) { if(Menu_GetAutoIO(menu_station_list)) { int selection = Menu_IsChosen(menu_station_list); if(selection != -1) { if(selection == 0) { // back if(strcmp(getStationsParentGenre(), "X") == 0) { // go to shoutcast menu Screen_Goto(SCREEN_SHOUTCAST); } else { // go to genre list setShoutcastGenreParent(getStationsParentGenre()); Screen_Goto(SCREEN_SHOUTCAST_GENRE); } } else { // show play/as_favorite/cancel menu Menu_SetAutoIO(menu_station_list, 0); Screen_ForceRedraw(); } } } else { int selection = Menu_IsChosen(menu_play_fav); if(selection != -1) { Menu_SetAutoIO(menu_station_list, 1); Screen_ForceRedraw(); if(selection == 0) { // play ShoutcastStation* info = getChosenStation((int)Menu_GetItemTag(menu_station_list, Menu_GetSelectedItem(menu_station_list))); StationInfo* station = parseShoutcastList(info); station->genre = getCurrentGenre(); playStation(station); free(station->url); free(station); } else if(selection == 1) { // add to station list ShoutcastStation* sc_stat = getChosenStation((int)Menu_GetItemTag(menu_station_list, Menu_GetSelectedItem(menu_station_list))); StationInfo* stat = parseShoutcastList(sc_stat); StationInfo* info = (StationInfo*)malloc(sizeof(StationInfo)); info->tag = '\0'; info->name = stat->name; info->url = stat->url; info->genre = getCurrentGenre(); ArrayList* stations = readStations(); AList_Add(stations, info); writeStations(stations); AList_Delete(stations, AList_Length(stations) - 1); freeStations(stations); AList_Destroy(stations); free(stat->url); free(stat); free(info); } else if(selection == 2) { // cancel // do nothing } } } } // --------------------------------------------------------------------------- else if(screen == SCREEN_SHOUTCAST_SEARCH) { if(Keyboard_IsConfirmed()) { char buffer[256]; sprintf(buffer, Settings_Get("shoutcast", "search_url"), Keyboard_GetText()); setShoutcastListUrl(buffer); setStationsParentGenre("X"); setCurrentGenre(" "); Screen_Goto(SCREEN_SHOUTCAST_LIST); } } // --------------------------------------------------------------------------- else if(screen == SCREEN_MANAGE_STATION) { if(Menu_GetAutoIO(menu_m_station)) { // handle station list menu int selection = Menu_IsChosen(menu_m_station); if(selection != -1) { // show menu Menu_SetAutoIO(menu_m_station, 0); Menu_ScrollTo(menu_m_menu, 0); Screen_ForceRedraw(); } } else { if(Menu_GetAutoIO(menu_m_menu)) { // handle station menu int selection = Menu_IsChosen(menu_m_menu); if(selection == 0) { // do nothing (cancel) } else if(selection == 1) { // move -> handled below } else if(selection == 2) { deleteStation(Menu_GetSelectedItem(menu_m_station)); Screen_Goto(SCREEN_MANAGE_STATION); } // close menu if(selection != -1) { if(selection == 1) { // move -> disable all menus Menu_SetAutoIO(menu_m_menu, 0); Menu_SetTitleTag(menu_m_station, Menu_GetSelectedItem(menu_m_station), '*'); Screen_ForceRedraw(); } else { Menu_SetAutoIO(menu_m_station, 1); Screen_ForceRedraw(); } } } else { // moving stations if(IO_GetButton(0)) { // we are done Menu_SetTitleTag(menu_m_station, Menu_GetSelectedItem(menu_m_station), 0); ArrayList* new_stations = AList_Create(); int i; for(i = 0; i < Menu_GetItems(menu_m_station); i++) { StationInfo* info = Menu_GetItemTag(menu_m_station, i); AList_Add(new_stations, info); } writeStations(new_stations); AList_Destroy(new_stations); Menu_SetAutoIO(menu_m_menu, 1); Menu_SetAutoIO(menu_m_station, 1); Screen_ForceRedraw(); } else { int8_t rotary = IO_GetRotaryValue(); if(rotary != 0) { int index = Menu_GetSelectedItem(menu_m_station); int new_index = index + ((rotary > 0) ? 1 : -1); Menu_SwapItems(menu_m_station, index, new_index); Menu_Scroll(menu_m_station, (rotary > 0) ? 1 : -1); } } } } } // --------------------------------------------------------------------------- else if(screen == SCREEN_TIMEOUT) { if(IO_GetButton(0)) { // go back to settings char buffer[8]; sprintf(buffer, "%d", Timeout_Get()); Settings_Add("hardware", "timeout", buffer); Settings_Save(settings_file); GLCDD_BacklightTimeout(Timeout_Get()); Screen_Goto(SCREEN_SETTINGS); } } // --------------------------------------------------------------------------- // home button if(IO_GetButton(1)) Screen_Goto(SCREEN_MAIN); // play/stop button if(IO_GetButton(2)) { if(screen != SCREEN_USB) { // stop music stopMusic(); } else { // play folder int i; FILE* f = fopen("/tmp/playlist1.m3u", "w"); for(i = 0; i < Menu_GetItems(menu_usb); i++) { // a file, add it to the list if((int)Menu_GetItemTag(menu_usb, i) == 0) { fprintf(f, "%s/%s\r\n", usb_root, Menu_GetItemText(menu_usb, i)); } } fclose(f); char cmd[128]; sprintf(cmd, "%s /tmp/playlist1.m3u > /tmp/playlist.m3u", Settings_Get("programs", "shuffle")); ignore_result(system(cmd)); playUSB("/tmp/playlist.m3u"); } } // end of snooze time if(checkSnoozeStop()) { // stop the music stopMusic(); // go to main screen Screen_Goto(SCREEN_MAIN); } // (1) button if(IO_GetButton(3)) playFavorite(1); // (2) button if(IO_GetButton(4)) playFavorite(2); // (3) button if(IO_GetButton(5)) playFavorite(3); // (4) button if(IO_GetButton(6)) playFavorite(4); Screen_Draw(); GLCDD_BacklightUpdate(); usleep(100); //sleep(1); } // really no need to cleanup, as firmware runs as long as device is powered // plus, the operating system frees all resources anyway }
void GraphicAdmin::init() { CID::CIDLog("GraphicAdmin", "winAPI init"); wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, D_WINDOW_NAME, NULL }; RegisterClassEx(&wc); hWnd = CreateWindow( D_WINDOW_NAME, D_WINDOW_NAME, WS_OVERLAPPEDWINDOW, 100, 100, D_WINDOW_WIDTH, D_WINDOW_HEIGHT, NULL, NULL, wc.hInstance, NULL ); ShowWindow(hWnd, SW_SHOWDEFAULT); UpdateWindow(hWnd); CID::CIDLog("GraphicAdmin", "d3d Init"); g_pD3D = Direct3DCreate9(D3D_SDK_VERSION); D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Windowed = true; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; d3dpp.BackBufferWidth = D_WINDOW_WIDTH; d3dpp.BackBufferHeight = D_WINDOW_HEIGHT; g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice ); createFont(); createSprite(); }
Font* DosDisk_ns::loadFont(const char* name) { char path[PATH_LEN]; sprintf(path, "%scnv.cnv", name); return createFont(name, loadCnv(path)); }
Font::Font(std::string path, Viewport* vp): _vp(vp) { if(!createFont(path)) std::cerr << "could not create font" << std::endl; }
int main() { lightDir.x=0.5; lightDir.y=.7; lightDir.z=-0.5; kmVec3Normalize(&lightDir,&lightDir); // creates a window and GLES context // create a window and GLES context if (!glfwInit()) exit(EXIT_FAILURE); window = glfwCreateWindow(width, height, "I N V A D E R S ! ! !", NULL, NULL); if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } glfwSetWindowSizeCallback(window,window_size_callback); glfwMakeContextCurrent(window); // all the shaders have at least texture unit 0 active so // activate it now and leave it active glActiveTexture(GL_TEXTURE0); // The obj shapes and their textures are loaded cubeTex = loadPNG("resources/textures/dice.png"); loadObj(&cubeObj, "resources/models/cube.gbo", "resources/shaders/textured.vert", "resources/shaders/textured.frag"); shipTex = loadPNG("resources/textures/shipv2.png"); loadObjCopyShader(&shipObj,"resources/models/ship.gbo",&cubeObj); alienTex = loadPNG("resources/textures/alien.png"); loadObjCopyShader(&alienObj, "resources/models/alien.gbo", &cubeObj); shotTex = loadPNG("resources/textures/shot.png"); loadObjCopyShader(&shotObj, "resources/models/shot.gbo", &cubeObj); expTex = loadPNG("resources/textures/explosion.png"); playerPos.x = 0; playerPos.y = 0; playerPos.z = 0; kmMat4Identity(&view); pEye.x = 0; pEye.y = 2; pEye.z = 4; pCenter.x = 0; pCenter.y = 0; pCenter.z = -5; pUp.x = 0; pUp.y = 1; pUp.z = 0; kmMat4LookAt(&view, &pEye, &pCenter, &pUp); // projection matrix, as distance increases // the way the model is drawn is effected kmMat4Identity(&projection); kmMat4PerspectiveProjection(&projection, 45, (float)width/ height, 0.1, 1000); glViewport(0, 0, width,height); // these two matrices are pre combined for use with each model render kmMat4Assign(&vp, &projection); kmMat4Multiply(&vp, &vp, &view); // initialises glprint's matrix shader and texture initGlPrint(width,height); font1=createFont("resources/textures/font.png",0,256,16,16,16); font2=createFont("resources/textures/bigfont.png",32,512,9.5,32,48); glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_BLEND); // only used by glprintf glEnable(GL_DEPTH_TEST); int num_frames = 0; bool quit = false; resetAliens(); for (int n = 0; n < MAX_PLAYER_SHOTS; n++) { playerShots[n].alive = false; } initPointClouds("resources/shaders/particle.vert", "resources/shaders/particle.frag",(float)width/24.0); for (int n = 0; n < MAX_ALIENS; n++) { aliens[n].explosion=createPointCloud(40); resetExposion(aliens[n].explosion); // sets initials positions } glClearColor(0, .5, 1, 1); while (!quit) { // the main loop clock_gettime(0,&ts); // note the time BEFORE we start to render the current frame glfwPollEvents(); if (glfwGetKey(window,GLFW_KEY_ESCAPE)==GLFW_PRESS || glfwWindowShouldClose(window)) quit = true; float rad; // radians rotation based on frame counter glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); frame++; rad = frame * (0.0175f * 2); //kmMat4Identity(&model); kmMat4Translation(&model, playerPos.x, playerPos.y, playerPos.z); playerCroll += (PIDcal(playerRoll, playerCroll, &playerPre_error, &playerIntegral) / 2); // kmMat4RotationPitchYawRoll(&model, 0, 3.1416, playerCroll * 3); // kmMat4RotationYawPitchRoll(&rot,0,3.1416,-playerCroll*3); kmMat4Multiply(&model, &model, &rot); kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); kmMat4Assign(&mv, &view); kmMat4Multiply(&mv, &mv, &model); glBindTexture(GL_TEXTURE_2D, shipTex); drawObj(&shipObj, &mvp, &mv, lightDir, viewDir); glPrintf(50 + sinf(rad) * 16, 240 + cosf(rad) * 16, font2,"frame=%i", frame); kmVec3 tmp; playerFireCount--; if (glfwGetKey(window,GLFW_KEY_LEFT_CONTROL)==GLFW_PRESS && playerFireCount < 0) { struct playerShot_t *freeShot; freeShot = getFreeShot(); if (freeShot != 0) { playerFireCount = 15; freeShot->alive = true; kmVec3Assign(&freeShot->pos, &playerPos); } } for (int n = 0; n < MAX_PLAYER_SHOTS; n++) { if (playerShots[n].alive) { playerShots[n].pos.z -= .08; if (playerShots[n].pos.z < -10) playerShots[n].alive = false; //kmMat4Identity(&model); kmMat4Translation(&model, playerShots[n].pos.x, playerShots[n].pos.y, playerShots[n].pos.z); //kmMat4RotationPitchYawRoll(&model, rad * 4, 0, // -rad * 4); kmMat4RotationYawPitchRoll(&rot,rad*4,0,-rad*4); kmMat4Multiply(&model,&model,&rot); kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); kmMat4Assign(&mv, &view); kmMat4Multiply(&mv, &mv, &model); glBindTexture(GL_TEXTURE_2D, shotTex); drawObj(&shotObj, &mvp, &mv, lightDir, viewDir); } } playerRoll = 0; if (glfwGetKey(window,GLFW_KEY_LEFT)==GLFW_PRESS && playerPos.x > -10) { playerPos.x -= 0.1; playerRoll = .2; } if (glfwGetKey(window,GLFW_KEY_RIGHT)==GLFW_PRESS && playerPos.x < 10) { playerPos.x += 0.1; playerRoll = -.2; } pEye.x = playerPos.x * 1.25; pCenter.x = playerPos.x; pCenter.y = playerPos.y + 1; pCenter.z = playerPos.z; int deadAliens; deadAliens = 0; for (int n = 0; n < MAX_ALIENS; n++) { if (aliens[n].alive == true) { //kmMat4Identity(&model); kmMat4Translation(&model, aliens[n].pos.x, aliens[n].pos.y, aliens[n].pos.z); //kmMat4RotationPitchYawRoll(&model, -.4, 0, 0); kmMat4RotationYawPitchRoll(&rot,.2,0,0); kmMat4Multiply(&model,&model,&rot); kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); kmMat4Assign(&mv, &view); kmMat4Multiply(&mv, &mv, &model); glBindTexture(GL_TEXTURE_2D, alienTex); drawObj(&alienObj, &mvp, &mv, lightDir, viewDir); kmVec3 d; for (int i = 0; i < MAX_PLAYER_SHOTS; i++) { kmVec3Subtract(&d, &aliens[n].pos, &playerShots[i].pos); if (kmVec3Length(&d) < .7 && playerShots[i].alive) { aliens[n].alive = false; playerShots[i].alive = false; aliens[n].exploding = true; resetExposion(aliens[n].explosion); } } } if (aliens[n].alive != true && aliens[n].exploding != true) { deadAliens++; } } if (deadAliens == MAX_ALIENS) { resetAliens(); } // draw explosions after ALL aliens for (int n = 0; n < MAX_ALIENS; n++) { if (aliens[n].exploding==true) { kmMat4Identity(&model); kmMat4Translation(&model, aliens[n].pos.x, aliens[n].pos.y, aliens[n].pos.z); kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); glBindTexture(GL_TEXTURE_2D, expTex); drawPointCloud(aliens[n].explosion, &mvp); aliens[n].explosion->tick=aliens[n].explosion->tick+0.05; if (aliens[n].explosion->tick>1.25) { aliens[n].exploding=false; } else { // update the explosion for (int i=0; i<aliens[n].explosion->totalPoints; i++) { float t; t=aliens[n].explosion->tick; if (i>aliens[n].explosion->totalPoints/2) t=t/2.0; aliens[n].explosion->pos[i*3]=aliens[n].explosion->vel[i*3] * t; aliens[n].explosion->pos[i*3+1]=aliens[n].explosion->vel[i*3+1] * t; aliens[n].explosion->pos[i*3+2]=aliens[n].explosion->vel[i*3+2] * t; } } } } // move camera kmMat4LookAt(&view, &pEye, &pCenter, &pUp); kmMat4Assign(&vp, &projection); kmMat4Multiply(&vp, &vp, &view); kmVec3Subtract(&viewDir,&pEye,&pCenter); kmVec3Normalize(&viewDir,&viewDir); // dump values glPrintf(100, 280, font1,"eye %3.2f %3.2f %3.2f ", pEye.x, pEye.y, pEye.z); glPrintf(100, 296, font1,"centre %3.2f %3.2f %3.2f ", pCenter.x, pCenter.y, pCenter.z); glPrintf(100, 340, font1,"frame %i %i ", frame, frame % 20); glfwSwapBuffers(window); ts.tv_nsec+=20000000; // 1000000000 / 50 = 50hz less time to render the frame //thrd_sleep(&ts,NULL); // tinycthread usleep(20000); // while I work out why tinycthread that was working isnt.... :/ } glfwDestroyWindow(window); glfwTerminate(); return 0; }
mxFontObject::mxFontObject(char *file_name) { createFont(file_name); }