本文整理汇总了C++中Gfx类的典型用法代码示例。如果您正苦于以下问题:C++ Gfx类的具体用法?C++ Gfx怎么用?C++ Gfx使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Gfx类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
Camera::Camera(Gfx& gfx, EventManager& event_manager)
:
sensitivity(0.1),
joy_sensitivity(1.2),
gfx(gfx)
{
event_manager.add_handler(EventType::window_size_change, [&gfx](const Event&)
{
gfx.center_cursor();
});
}
示例2: BeginPaint
void Painter::OnWmPaint(HWND hwnd)
{
PAINTSTRUCT ps;
HDC dc = BeginPaint(hwnd, &ps);
gfx = CreateGdiplusGfx(dc);
ClientRect cr(hwnd);
gfx->SetSize(cr.dx, cr.dy); // TODO: get it from HDC and set during creation
GfxRect r = gfx->size;
gfx->DrawFilledRect(r, COL_WHITE);
r.Inflate(1, 3, 0, -2);
gfx->DrawFilledRect(r, COL_GRAY);
r.Inflate(-1);
gfx->DrawRect(r, COL_BLACK, 1.f);
delete gfx;
EndPaint(hwnd, &ps);
}
示例3: sizeof
void Jotter::bindVertexAttribs(const SPtr<Gfx>& gfx) const
{
Gfx* g = gfx.get();
size_t s = 0;
g->bindVertexPosition((uint8_t)s, (uint8_t)_pos_comps);
s += _pos_size;
if(_has_normal)
{
g->bindVertexNormal((uint8_t)s);
s += sizeof(Vec3);
}
if(_has_color)
{
g->bindVertexColor((uint8_t)s);
s += sizeof(Vec4);
}
ptrdiff_t c = _tc_sets;
for(ptrdiff_t i = 0; i < c; ++i)
{
g->bindVertexTexCoord((uint8_t)s, (uint8_t)i, (uint8_t)_tc_comps);
s += _tc_size;
}
}
示例4: AnalyzePalette
void Character::AnalyzePalette() {
Gfx *gfx = Gfx::Get();
border_color = gfx->MatchingColor(RGB(255, 255, 255));
ammo_color = gfx->MatchingColor(RGB(0, 255, 255));
ammo_color_dim = gfx->MatchingColor(RGB(0, 128, 128));
health_color = gfx->MatchingColor(RGB(255, 0, 0));
health_color_dim = gfx->MatchingColor(RGB(128, 0, 0));
}
示例5:
Game::Game(Gfx& gfx)
:
hovered_block(nullptr),
gfx(gfx),
camera(gfx, event_manager),
world(*this, "worlds/test"),
player_ptr(world.add_player("test_player")),
player(*player_ptr),
console(*this),
keybinder(console),
wireframe(false, [](const bool wireframe)
{
glPolygonMode(GL_FRONT_AND_BACK, wireframe ? GL_LINE : GL_FILL);
}),
delta_time(0),
fps(999),
render_distance(3)
{
Game::instance = this;
// these 2 must be added first (in this order!) to get the correct IDs
add_block<Block::None>("none");
add_block<Block::Air>("air");
add_block<Block::Test>("test");
add_block("dots");
add_block("eye");
add_block<Block::Teleporter>("teleporter");
add_block("marble");
add_block("white");
add_block("black");
add_block<Block::Light>("light");
add_block<Block::Glass>("glass");
block_type = block_registry.get_id("white");
gui = std::make_unique<Graphics::GUI::Play>(*this);
gui->init();
gfx.hook_events(event_manager);
add_commands();
console.run_line("exec binds");
update_framebuffer_size(gfx.window_size);
}
示例6: main
int main ( int argc, char** argv ) {
SDL_Texture* s1Texture = NULL;
SDL_Texture* s1TextureShift = NULL;
SDL_Rect s1Rect = { 0, 0, 18, 24 }; //player x y w h
SDL_Texture* e1Texture = NULL;
SDL_Rect e1Rect = { 310, 240, 16, 16 }; //enemy x y w h
Input *input = new Input();
Sprite *sprite = new Sprite();
Gfx *gfx = new Gfx();
General *general = new General();
float fps, frames, frameStartTime, frameEndTime;
gfx->gfxinit(screenw, screenh); // open window with 620x480 res. with 8 bit color
s1Texture = gfx->createTexture("gfx/s1.bmp", 0);
s1TextureShift = gfx->createTexture("gfx/s1sneek.bmp", 1);
e1Texture = gfx->createTexture("gfx/e1.bmp", 0);
/* program main loop */
while (!input->isGameDone()) {
// get time when frame starts
frameStartTime = SDL_GetTicks();
input->inputLoop();
sprite->move(input, s1Rect, e1Rect);
general->checkCollision(input, s1Rect, e1Rect, screenw, screenh);
gfx->clearScreen(100,0,0);
if (!input->isShiftPressed()) {
gfx->drawTexture(s1Texture, s1Rect);
} else {
gfx->drawTexture(s1TextureShift, s1Rect);
}
gfx->drawTexture(e1Texture, e1Rect);
gfx->update();
// get time at the end of frame after updating
frameEndTime = SDL_GetTicks();
// increment frames
++frames;
fps = frames / (SDL_GetTicks() / 1000);
// Supposed ms per frame is 16.6666ms since 1000/60
// if frame finishes early
if ((frameEndTime - frameStartTime) < (1000/60)) {
SDL_Delay((1000 / 60) - (frameEndTime - frameStartTime));
}
}
delete sprite;
delete input;
delete general;
gfx->close();
delete gfx;
return 0; // return success!
}
示例7: displayAnswers
void DialogueManager::displayAnswers() {
// create balloons
int id;
for (int i = 0; i < _numVisAnswers; ++i) {
id = _balloonMan->setDialogueBalloon(_visAnswers[i]._a->_text, 1, BalloonManager::kUnselectedColor);
assert(id >= 0);
_visAnswers[i]._balloon = id;
}
int mood = 0;
if (_numVisAnswers == 1) {
mood = _visAnswers[0]._a->speakerMood();
_balloonMan->setBalloonText(_visAnswers[0]._balloon, _visAnswers[0]._a->_text, BalloonManager::kNormalColor);
} else
if (_numVisAnswers > 1) {
mood = _visAnswers[0]._a->speakerMood();
_oldSelection = NO_ANSWER_SELECTED;
_selection = 0;
}
_faceId = _gfx->setItem(_answerer, _ballonPos._answerChar.x, _ballonPos._answerChar.y);
_gfx->setItemFrame(_faceId, mood);
}
示例8: displayQuestion
bool DialogueManager::displayQuestion() {
if (_q->textIsNull()) return false;
_balloonMan->setSingleBalloon(_q->_text, _ballonPos._questionBalloon.x, _ballonPos._questionBalloon.y, _q->balloonWinding(), BalloonManager::kNormalColor);
_faceId = _gfx->setItem(_questioner, _ballonPos._questionChar.x, _ballonPos._questionChar.y);
_gfx->setItemFrame(_faceId, _q->speakerMood());
return true;
}
示例9: runQuestion
void DialogueManager::runQuestion() {
if (_mouseButtons == kMouseLeftUp) {
_gfx->freeDialogueObjects();
transitionToState(NEXT_ANSWER);
}
}
示例10: selectAnswerN
int16 DialogueManager::selectAnswerN() {
_selection = _balloonMan->hitTestDialogueBalloon(_mousePos.x, _mousePos.y);
VisibleAnswer *oldAnswer = (_oldSelection == NO_ANSWER_SELECTED) ? NULL : &_visAnswers[_oldSelection];
VisibleAnswer *answer = &_visAnswers[_selection];
if (_selection != _oldSelection) {
if (_oldSelection != NO_ANSWER_SELECTED) {
_balloonMan->setBalloonText(oldAnswer->_balloon, oldAnswer->_a->_text, BalloonManager::kUnselectedColor);
}
if (_selection != NO_ANSWER_SELECTED) {
_balloonMan->setBalloonText(answer->_balloon, answer->_a->_text, BalloonManager::kSelectedColor);
_gfx->setItemFrame(_faceId, answer->_a->speakerMood());
}
}
_oldSelection = _selection;
if ((_mouseButtons == kMouseLeftUp) && (_selection != NO_ANSWER_SELECTED)) {
return _visAnswers[_selection]._index;
}
return NO_ANSWER_SELECTED;
}
示例11: runAnswer
void DialogueManager::runAnswer() {
_answerId = selectAnswer();
if (_answerId != NO_ANSWER_SELECTED) {
_cmdList = &_q->_answers[_answerId]->_commands;
_gfx->freeDialogueObjects();
transitionToState(NEXT_QUESTION);
}
}
示例12: main
int main(int argc, char *argv[]) {
FILE* fp = fopen("config.txt", "r");
if (fp) {
int a, b;
if (fscanf(fp," cores %d", &a) == 1) plotter.n_threads = a;
if (fscanf(fp," def_res %d %d", &a, &b) == 2) {
gfx.screen_w_default = a;
gfx.screen_h_default = b;
}
if (fscanf(fp," max_iter %d", &a) == 1) plotter.max_iter = a;
}
if (SDL_Init(SDL_INIT_EVERYTHING) == -1 || !gfx.init()) return 1;
plotter.init();
plotter.resize(gfx.get_screen_w(), gfx.get_screen_h());
plotter.plot();
while (true) {
frame_time = SDL_GetTicks();
input.update();
if (input.key_pressed(SDLK_ESCAPE) || input.is_quitting())
break;
if (input.key_down( SDLK_LCTRL ) &&
input.mouse_pressed(SDL_BUTTON_LEFT)) {
plotter.center();
} else if (input.mouse_pressed(SDL_BUTTON_LEFT)) {
if (input.key_down(SDLK_LSHIFT)) {
plotter.zoom(zoom_factor * 5);
} else {
plotter.zoom(zoom_factor);
}
} else if (input.mouse_pressed(SDL_BUTTON_RIGHT)) {
if (input.key_down(SDLK_LSHIFT)) {
plotter.zoom(1/(zoom_factor * 5));
} else {
plotter.zoom(1/zoom_factor);
}
}
if (input.key_pressed(SDLK_f)) {
plotter.end_plotting();
gfx.toggle_fullscreen();
plotter.resize(gfx.get_screen_w(), gfx.get_screen_h());
plotter.plot();
//zoom_on();
}
if (input.key_pressed(SDLK_p)) {
plotter.print_pos();
}
gfx.update();
int time_rem = 1000 / FPS - (SDL_GetTicks() - frame_time);
if (time_rem >= 5)
SDL_Delay(time_rem);
}
plotter.end_plotting();
SDL_Quit();
return 0;
}