/** Applies a 5x5 filter to monochrome image I (wrapping at the boundaries) */ static uint8 applyFilter( const uint8* I, int x, int y, int w, int h, const float filter[5][5]) { debugAssert(isEven(w)); debugAssert(isEven(h)); float sum = 0.0f; float denom = 0.0f; for (int dy = 0; dy < 5; ++dy) { int offset = ((y + dy + h - 2) % h) * w; for (int dx = 0; dx < 5; ++dx) { float f = filter[dy][dx]; sum += f * I[((x + dx + w - 2) % w) + offset]; denom += f; } } return (uint8)iClamp(iRound(sum / denom), 0, 255); }
ArticulatedModel::Instruction::Identifier::Identifier(const Any& a) { switch (a.type()) { case Any::NUMBER: id = ID(iRound(a.number())); a.verify(id >= 0, "Illegal ID"); break; case Any::STRING: name = a.string(); break; case Any::ARRAY: a.verifySize(0); if (a.name() == "root") { *this = root(); } else if (a.name() == "all") { *this = all(); } else { a.verify(false, "Illegal function call: " + a.name()); } break; default: a.verify(false, "Expected a name, integer ID, root(), or all()"); } }
std::string Matrix::toString(const std::string& name) const { std::string s; if (name != "") { s += format("%s = \n", name.c_str()); } s += "["; for (int r = 0; r < rows(); ++r) { for (int c = 0; c < cols(); ++c) { double v = impl->get(r, c); if (::fabs(v) < 0.00001) { // Don't print "negative zero" s += format("% 10.04g", 0.0); } else if (v == iRound(v)) { // Print integers nicely s += format("% 10.04g", v); } else { s += format("% 10.04f", v); } if (c < cols() - 1) { s += ","; } else if (r < rows() - 1) { s += ";\n "; } else { s += "]\n"; } } } return s; }
VideoOutput::Settings VideoOutput::Settings::CinepakAVI(int width, int height, float fps) { Settings s(CODEC_ID_CINEPAK, width, height, fps); s.extension = "avi"; s.description = "Cinepak AVI (.avi)"; s.bitrate = iRound(2000000.0 * ((double)s.width * s.height) / (640 * 480)); return s; }
VideoOutput::Settings VideoOutput::Settings::WMV(int width, int height, float fps) { Settings s(CODEC_ID_WMV2, width, height, fps); s.extension = "wmv"; s.description = "Windows Media Video 2 (.wmv)"; s.bitrate = iRound(3000000.0 * ((double)s.width * s.height) / (640 * 480)); return s; }
void Texture::Preprocess::modulateImage(ImageFormat::Code fmt, void* _byte, int n) const { debugAssertM( (fmt == ImageFormat::CODE_RGB8) || (fmt == ImageFormat::CODE_RGBA8) || (fmt == ImageFormat::CODE_R8) || (fmt == ImageFormat::CODE_L8), "Texture preprocessing only implemented for 1, 3, 4 8-bit channels."); uint8* byte = static_cast<uint8*>(_byte); // Make a lookup table uint8 adjust[4][256]; for (int c = 0; c < 4; ++c) { for (int i = 0; i < 256; ++i) { float s = float(pow((i * modulate[c]) / 255, gammaAdjust) * 255); adjust[c][i] = iClamp(iRound(s), 0, 255); } } switch (fmt) { case ImageFormat::CODE_RGBA8: for (int i = 0; i < n; ++i) { for (int c = 0; c < 3; ++c, ++i) { byte[i] = adjust[c][byte[i]]; } } if (convertToPremultipliedAlpha) { for (int i = 0; i < n; i += 4) { int a = byte[i + 3]; for (int c = 0; c < 3; ++c) { byte[i + c] = (int(byte[i + c]) * a) / 255; } } } break; case ImageFormat::CODE_RGB8: for (int i = 0; i < n; ) { for (int c = 0; c < 3; ++c, ++i) { byte[i] = adjust[c][byte[i]]; } } break; case ImageFormat::CODE_R8: case ImageFormat::CODE_L8: for (int i = 0; i < n; ++i) { byte[i] = adjust[0][byte[i]]; } break; default:; } }
VideoOutput::Settings VideoOutput::Settings::MPEG4(int width, int height, float fps) { Settings s(CODEC_ID_H264, width, height, fps); // About 6 * 1500 kb/s for 640 * 480 gives high quality at a // reasonable file size. s.bitrate = iRound(6 * 1500000.0 * ((double)s.width * s.height) / (640 * 480)); s.extension = "mp4"; s.description = "MPEG-4/H.264 (.mp4)"; return s; }
void ToneMap::makeGammaCorrectionTextures() { if (RG.notNull() || (profile == NO_TONE)) { return; } // The inverse gamma ramp function G3D::uint8 ramp[256]; for (int i = 0; i < 256; ++i) { // Linear //ramp[i] = i; // Inverse power const double A = 1.9; // Brighten the screen image by 1.0 / 0.75 = 1.34, since we darkened the // scene when rendering to avoid saturation. ramp[i] = iClamp(iRound((1.0 - pow(1.0 - i/255.0, A)) * 255.0 / 0.75), 0, 255); // Log // const double A = 10, B = 1; // ramp[i] = iRound(((log(A*i/255.0 + B) - log(B)) / // (log(A+B) - log(B))) * 255.0); } GImage data(256, 256, 3); for (int g = 0; g < 256; ++g) { for (int r = 0; r < 256; ++r) { Color3uint8& p = data.pixel3(r, g); p.r = ramp[r]; p.g = ramp[g]; p.b = 0; } } // MIP-mapping causes bad interpolation for some reason RG = Texture::fromGImage("RG Gamma", data, TextureFormat::RGB8, Texture::DIM_2D, Texture::Settings::video()); if (profile != PS20) { // On PS20 we can re-use the original RG texture data.resize(256, 1, 3); for (int b = 0; b < 256; ++b) { Color3uint8& p = data.pixel3(b, 0); p.r = 0; p.g = 0; p.b = ramp[b]; } B = Texture::fromGImage("B Gamma", data, TextureFormat::RGB8, Texture::DIM_2D, Texture::Settings::video()); } }
void GFont::adjustINIWidths(const String& srcFile, const String& dstFile, float scale) { TextInput in(srcFile); TextOutput out(dstFile); in.readSymbols("[", "Char", "Widths", "]"); out.printf("[Char Widths]\n"); for (int i = 0; i <= 255; ++i) { in.readNumber(); in.readSymbol("="); int w = (int)in.readNumber(); w = iRound(w * scale); out.printf("%d=%d\n", i, w); } out.commit(); }
BumpMap::Settings::Settings(const Any& any) { *this = Settings(); any.verifyName("BumpMap::Settings"); for (Any::AnyTable::Iterator it = any.table().begin(); it.hasMore(); ++it) { const std::string& key = toLower(it->key); if (key == "iterations") { iterations = iMax(0, iRound(it->value.number())); } else if (key == "scale") { scale = it->value; } else if (key == "bias") { bias = it->value; } else { any.verify(false, "Illegal key: " + it->key); } } }
void VideoRecordDialog::startRecording() { debugAssert(isNull(m_video)); // Create the video file VideoOutput::Settings settings = m_settingsTemplate[m_templateIndex]; OSWindow* window = const_cast<OSWindow*>(OSWindow::current()); settings.width = window->width(); settings.height = window->height(); if (m_halfSize) { settings.width /= 2; settings.height /= 2; } double kps = 1000; double baseRate = 1500; if (settings.codec == VideoOutput::CODEC_ID_WMV2) { // WMV is lower quality baseRate = 3000; } settings.bitrate = iRound(m_quality * baseRate * kps * settings.width * settings.height / (640 * 480)); settings.fps = m_playbackFPS; const String& filename = ScreenshotDialog::nextFilenameBase(m_filenamePrefix) + "." + m_settingsTemplate[m_templateIndex].extension; m_video = VideoOutput::create(filename, settings); if (m_app) { m_oldSimTimeStep = m_app->simStepDuration(); m_oldRealTimeTargetDuration = m_app->realTimeTargetDuration(); m_app->setFrameDuration(1.0f / m_recordFPS, GApp::MATCH_REAL_TIME_TARGET); } m_recordButton->setCaption("Stop (" + m_hotKeyString + ")"); setVisible(false); // Change the window caption as well const String& c = window->caption(); const String& appendix = " - Recording " + m_hotKeyString + " to stop"; if (! endsWith(c, appendix)) { window->setCaption(c + appendix); } }
void GPUProgram::BindingTable::parseConstant(TextInput& ti) { if (consumeSymbol(ti, "c") && consumeSymbol(ti, "[")) { // constant Token t = ti.peek(); if (t.type() == Token::NUMBER) { Binding binding; binding.source = CONSTANT; binding.type = FLOAT4; binding.slot = iRound(ti.readNumber()); if (consumeSymbol(ti, "]") && consumeSymbol(ti, "=")) { for (int i = 0; i < 4; ++i) { t = ti.peek(); if (t.type() == Token::NUMBER) { binding.vector[i] = ti.readNumber(); } } bindingArray.append(binding); } } } }
Color1uint8::Color1uint8(const class Color1& c) : value(iMin(255, iRound(c.value * 256))) { }
void Film::exposeAndRender(RenderDevice* rd, const Texture::Ref& input, int downsample) { debugAssertM(downsample == 1, "Downsampling not implemented in this release"); if (m_framebuffer.isNull()) { init(); } const int w = input->width(); const int h = input->height(); int blurDiameter = iRound(m_bloomRadiusFraction * 2.0f * max(w, h)); if (isEven(blurDiameter)) { ++blurDiameter; } // Blur diameter for the vertical blur (at half resolution) int halfBlurDiameter = blurDiameter / 2; if (isEven(halfBlurDiameter)) { ++halfBlurDiameter; } float bloomStrength = m_bloomStrength; if (halfBlurDiameter <= 1) { // Turn off bloom; the filter radius is too small bloomStrength = 0; } // Allocate intermediate buffers, perhaps because the input size is different than was previously used. if (m_temp.isNull() || (m_temp->width() != w/2) || (m_temp->height() != h/2)) { // Make smaller to save fill rate, since it will be blurry anyway m_preBloom = Texture::createEmpty("Film PreBloom", w, h, m_intermediateFormat, Texture::defaultDimension(), Texture::Settings::video()); m_temp = Texture::createEmpty("Film Temp", w/2, h/2, m_intermediateFormat, Texture::defaultDimension(), Texture::Settings::video()); m_blurry = Texture::createEmpty("Film Blurry", w/4, h/4, m_intermediateFormat, Texture::defaultDimension(), Texture::Settings::video()); // Clear the newly created textures m_preBloom->clear(Texture::CUBE_POS_X, 0, rd); m_temp->clear(Texture::CUBE_POS_X, 0, rd); m_blurry->clear(Texture::CUBE_POS_X, 0, rd); m_framebuffer->set(Framebuffer::COLOR_ATTACHMENT0, m_preBloom); m_tempFramebuffer->set(Framebuffer::COLOR_ATTACHMENT0, m_temp); m_blurryFramebuffer->set(Framebuffer::COLOR_ATTACHMENT0, m_blurry); } rd->push2D(); // Bloom if (bloomStrength > 0) { Framebuffer::Ref oldFB = rd->framebuffer(); rd->setFramebuffer(m_framebuffer); rd->clear(); m_preBloomShader->args.set("sourceTexture", input); m_preBloomShader->args.set("exposure", m_exposure); rd->setShader(m_preBloomShader); Draw::fastRect2D(m_preBloom->rect2DBounds(), rd); rd->setFramebuffer(m_tempFramebuffer); rd->clear(); // Blur vertically GaussianBlur::apply(rd, m_preBloom, Vector2(0, 1), blurDiameter, m_temp->vector2Bounds()); // Blur horizontally rd->setFramebuffer(m_blurryFramebuffer); rd->clear(); GaussianBlur::apply(rd, m_temp, Vector2(1, 0), halfBlurDiameter, m_blurry->vector2Bounds()); rd->setFramebuffer(oldFB); } { // Combine, fix saturation, gamma correct and draw m_shader->args.set("sourceTexture", input); m_shader->args.set("bloomTexture", (bloomStrength > 0) ? m_blurry : Texture::zero()); m_shader->args.set("bloomStrengthScaled", bloomStrength * 10.0); m_shader->args.set("exposure", m_exposure); m_shader->args.set("invGamma", 1.0f / m_gamma); rd->setShader(m_shader); Draw::fastRect2D(input->rect2DBounds(), rd); } rd->pop2D(); }
void App::onGraphics (RenderDevice *rd, Array< SurfaceRef > &posed3D, Array< Surface2DRef > &posed2D) { rd->setColorClearValue(Color3::white()); rd->clear(); doFunStuff(); rd->push2D(); int w = rd->width(); int h = rd->height(); /////////////////////////////////////// // Left panel # define LABEL(str) p.y += titleFont->draw2D(rd, str, p - Vector2((float)w * 0.0075f, 0), s * 2, Color3::white() * 0.4f).y # define PRINT(str) p.y += reportFont->draw2D(rd, str, p, s, Color3::black()).y int x0 = int(w * 0.015f); // Cursor position Vector2 p(x0, h * 0.02f); // Font size float s = w * 0.013; LABEL("Shaders"); PRINT(std::string("Combiners: ") + combineShader); PRINT(std::string("Assembly: ") + asmShader); PRINT(std::string("GLSL: ") + glslShader); p.y += s * 2; LABEL("Extensions"); PRINT(std::string("FSAA: ") + ((GLCaps::supports("WGL_ARB_multisample") || GLCaps::supports("GL_ARB_multisample")) ? "Yes" : "No")); PRINT(std::string("Two-sided Stencil: ") + ((GLCaps::supports_two_sided_stencil() ? "Yes" : "No"))); PRINT(std::string("Stencil Wrap: ") + (GLCaps::supports("GL_EXT_stencil_wrap") ? "Yes" : "No")); PRINT(std::string("Texture Compression: ") + (GLCaps::supports("GL_EXT_texture_compression_s3tc") ? "Yes" : "No")); PRINT(std::string("Shadow Maps: ") + (GLCaps::supports("GL_ARB_shadow") ? "Yes" : "No")); PRINT(std::string("Frame Buffer Object: ") + (GLCaps::supports("GL_EXT_framebuffer_object") ? "Yes" : "No")); PRINT(std::string("Vertex Arrays: ") + (GLCaps::supports_GL_ARB_vertex_buffer_object() ? "Yes" : "No")); /////////////////////////////////////// // Right Panel x0 = int(w * 0.6f); // Cursor position p = Vector2(x0, h * 0.02f); // Graphics Card LABEL("Graphics Card"); rd->setTexture(0, cardLogo); Draw::rect2D(Rect2D::xywh(p.x - s * 6, p.y, s * 5, s * 5), rd); rd->setTexture(0, NULL); PRINT(GLCaps::vendor().c_str()); PRINT(GLCaps::renderer().c_str()); PRINT(format("Driver Version %s", GLCaps::driverVersion().c_str())); # ifdef G3D_WIN32 PRINT(format("%d MB Video RAM", DXCaps::videoMemorySize() / (1024 * 1024))); { uint32 ver = DXCaps::version(); PRINT(format("DirectX %d.%d", ver/100, ver%100)); } # endif p.y += s * 2; // Processor LABEL("Processor"); rd->setTexture(0, chipLogo); Draw::rect2D(Rect2D::xywh(p.x - s * 6, p.y, s * 5, s * 5), rd); rd->setTexture(0, NULL); PRINT(System::cpuVendor().c_str()); PRINT(System::cpuArchitecture().c_str()); Array<std::string> features; if (System::has3DNow()) { features.append("3DNow"); } if (System::hasMMX()) { features.append("MMX"); } if (System::hasSSE()) { features.append("SSE"); } if (System::hasSSE2()) { features.append("SSE2"); } if (chipSpeed != "") { PRINT(chipSpeed + " " + stringJoin(features, '/')); } else { PRINT(stringJoin(features, '/')); } p.y += s * 2; // Operating System LABEL("OS"); rd->setTexture(0, osLogo); Draw::rect2D(Rect2D::xywh(p.x - s * 6, p.y - s * 2, s * 5, s * 5), rd); rd->setTexture(0, NULL); if (beginsWith(System::operatingSystem(), "Windows 5.0")) { PRINT("Windows 2000"); } else if (beginsWith(System::operatingSystem(), "Windows 5.1")) { PRINT("Windows XP"); } PRINT(System::operatingSystem().c_str()); p.y += s * 3; x0 = int(w - s * 10); titleFont->draw2D(rd, "Features", p - Vector2(w * 0.0075f, 0), s * 2, Color3::white() * 0.4f); p.y += reportFont->draw2D(rd, format("f%d", featureRating), Vector2(x0, p.y), s*2, Color3::red() * 0.5).y; drawBar(rd, featureRating, p); // Designed to put NV40 at 50 performanceRating = log(rd->stats().frameRate) * 15.0f; p.y += s * 4; performanceButton = Rect2D::xywh(p, titleFont->draw2D(rd, "Speed", p - Vector2(w * 0.0075f, 0), s * 2, Color3::white() * 0.4f)); { float spd = iRound(performanceRating * 10) / 10.0f; p.y += reportFont->draw2D(rd, format("%5.1f", spd), Vector2(x0 - s*2, p.y), s*2, Color3::red() * 0.5).y; } drawBar(rd, (int)min(performanceRating, 100.0f), p); p.y += s * 4; titleFont->draw2D(rd, "Quality", p - Vector2(w * 0.0075f, 0), s * 2, Color3::white() * 0.4f); p.y += reportFont->draw2D(rd, quality(bugCount), Vector2(x0, p.y), s*2, Color3::red() * 0.5f).y; drawBar(rd, iClamp(100 - bugCount * 10, 0, 100), p); # undef PRINT p.y = h - 50; # define PRINT(str) p.y += reportFont->draw2D(rd, str, p, 8, Color3::black()).y; PRINT("These ratings are based on the performance of G3D apps."); PRINT("They may not be representative of overall 3D performance."); PRINT("Speed is based on both processor and graphics card. Upgrading"); PRINT("your graphics driver may improve Quality and Features."); # undef PRINT # undef LABEL switch (popup) { case NONE: break; case PERFORMANCE: { // Draw the popup box Rect2D box = drawPopup("Performance Details"); p.x = box.x0() + 10; p.y = box.y0() + 30; Vector2 spacing(box.width() / 6.5, 0); std::string str; float factor = 3 * vertexPerformance.numTris / 1e6; # define PRINT(cap, val) \ reportFont->draw2D(rd, cap, p, s, Color3::black());\ reportFont->draw2D(rd, (vertexPerformance.val[0] > 0) ? \ format("%5.1f", vertexPerformance.val[0]) : \ std::string("X"), p + spacing * 3, s, Color3::red() * 0.5, Color4::clear(), GFont::XALIGN_RIGHT);\ reportFont->draw2D(rd, (vertexPerformance.val[0] > 0) ? \ format("%5.1f", factor * vertexPerformance.val[0]) : \ std::string("X"), p + spacing * 4, s, Color3::red() * 0.5, Color4::clear(), GFont::XALIGN_RIGHT);\ reportFont->draw2D(rd, (vertexPerformance.val[1] > 0) ? \ format("%5.1f", vertexPerformance.val[1]) : \ std::string("X"), p + spacing * 5, s, Color3::red() * 0.5, Color4::clear(), GFont::XALIGN_RIGHT);\ p.y += reportFont->draw2D(rd, (vertexPerformance.val[1] > 0) ? \ format("%5.1f", factor * vertexPerformance.val[1]) : \ std::string("X"), p + spacing * 6, s, Color3::red() * 0.5, Color4::clear(), GFont::XALIGN_RIGHT).y; reportFont->draw2D(rd, "Incoherent", p + spacing * 3.5, s, Color3::black(), Color4::clear(), GFont::XALIGN_RIGHT); p.y += reportFont->draw2D(rd, "Coherent", p + spacing * 5.5, s, Color3::black(), Color4::clear(), GFont::XALIGN_RIGHT).y; reportFont->draw2D(rd, "FPS*", p + spacing * 3, s, Color3::black(), Color4::clear(), GFont::XALIGN_RIGHT); reportFont->draw2D(rd, "MVerts/s", p + spacing * 4, s, Color3::black(), Color4::clear(), GFont::XALIGN_RIGHT); reportFont->draw2D(rd, "FPS*", p + spacing * 5, s, Color3::black(), Color4::clear(), GFont::XALIGN_RIGHT).y; p.y += reportFont->draw2D(rd, "MVerts/s", p + spacing * 6, s, Color3::black(), Color4::clear(), GFont::XALIGN_RIGHT).y; PRINT("glBegin/glEnd", beginEndFPS); PRINT("glDrawElements", drawElementsRAMFPS); PRINT(" + VBO", drawElementsVBOFPS); PRINT(" + uint16", drawElementsVBO16FPS); PRINT(" + gl interleave", drawElementsVBOIFPS); PRINT(" + manual interleave", drawElementsVBOIMFPS); PRINT(" (without shading)", drawElementsVBOPeakFPS); reportFont->draw2D(rd, "glDrawArrays", p, s, Color3::black()); reportFont->draw2D(rd, (vertexPerformance.drawArraysVBOPeakFPS > 0) ? \ format("%5.1f", vertexPerformance.drawArraysVBOPeakFPS) : \ std::string("X"), p + spacing * 5, s, Color3::red() * 0.5, Color4::clear(), GFont::XALIGN_RIGHT);\ p.y += reportFont->draw2D(rd, (vertexPerformance.drawArraysVBOPeakFPS > 0) ? \ format("%5.1f", factor * vertexPerformance.drawArraysVBOPeakFPS) : \ std::string("X"), p + spacing * 6, s, Color3::red() * 0.5, Color4::clear(), GFont::XALIGN_RIGHT).y; # undef PRINT p.y += s; p.y += reportFont->draw2D(rd, format("* FPS at %d k polys/frame.", iRound(vertexPerformance.numTris / 1000.0)), p + Vector2(20, 0), s, Color3::black()).y; } } rd->pop2D(); }
Vector4int8::Vector4int8(const Vector3& source, int8 w) : w(w) { x = iClamp(iRound(source.x), -128, 127); y = iClamp(iRound(source.y), -128, 127); z = iClamp(iRound(source.z), -128, 127); }
Vector4int8::Vector4int8(const Vector4& source) { x = iClamp(iRound(source.x), -128, 127); y = iClamp(iRound(source.y), -128, 127); z = iClamp(iRound(source.z), -128, 127); w = iClamp(iRound(source.w), -128, 127); }
Any::operator int() const { beforeRead(); return iRound(number()); }
Color4uint8::Color4uint8(const class Color4& c) { r = iMin(255, iRound(c.r * 256)); g = iMin(255, iRound(c.g * 256)); b = iMin(255, iRound(c.b * 256)); a = iMin(255, iRound(c.a * 256)); }
void GPUProgram::BindingTable::parseVariable(TextInput& ti) { std::string name; // #var float4 osLight : : c[4] : 1 : 1 // #var float3 vin.v0 : $vin.POSITION : ATTR0 : 2 : 1 Token t = ti.peek(); if (t.type() != Token::SYMBOL) { goto abort; } // get the binding's type ti.readSymbol(); Type type; if (! CgType(t.string(), type)) { alwaysAssertM(false, std::string("Unsupported type: \"") + t.string() + "\""); } t = ti.peek(); if (t.type() != Token::SYMBOL) { goto abort; } // read the binding name name = ti.readSymbol(); if (! consumeSymbol(ti, ":")) { goto abort; } // see if it is the vertex or a constant register t = ti.peek(); if (t.type() != Token::SYMBOL) { goto abort; } // Sometimes there is an extra token between the colons if (t.string() != ":") { ti.readSymbol(); t = ti.peek(); } if (! consumeSymbol(ti, ":")) { goto abort; } // read the register number t = ti.peek(); if (t.type() != Token::SYMBOL) { goto abort; } // Consume the symbol we just peeked ti.readSymbol(); if (t.string() == "texunit") { // We're reading a texture unit } else if (t.string() == "c") { // We're reading a regular variable; parse the open bracket if (! consumeSymbol(ti, "[")) { goto abort; } } else if ((t.type() == Token::SYMBOL) && (t.string() == ":")) { // Unused variable; must be present but is not bound Binding binding; binding.source = VARIABLE; binding.type = type; binding.name = name; binding.slot = Binding::UNASSIGNED; bindingArray.append(binding); return; } else { // Something unexpected happened. goto abort; } t = ti.peek(); if (t.type() == Token::NUMBER) { int slot = iRound(ti.readNumber()); Binding binding; binding.source = VARIABLE; binding.type = type; binding.name = name; binding.slot = slot; bindingArray.append(binding); } abort: ;// Jump here if anything unexpected is encountered during parsing }
void GlutWindow::getRelativeMouseState(int& x, int& y, uint8& b) const { x = iRound(mouse.x); y = iRound(mouse.y); b = mouseButtons; }
void GlutWindow::setRelativeMousePosition(double x, double y) { glutWarpPointer(iRound(x), iRound(y)); }
static std::string formatDimensions(const std::string& description, const Vector2& dimension) { return format("%s: %dx%d", description.c_str(), iRound(dimension.x), iRound(dimension.y)); }
int keyRepeatData::getRateInSDLFormat () const { return iRound(1000.0 / rate); }
void doGraphics() { bool screenshot = singleScreen || batchScreen; LightingParameters lighting(G3D::toSeconds(10, 00, 00, AM)); // Some models have part of their geometry stored in the "weapon" file. // Darth Maul, for example, has his lower half in the weapon. const double footy = 0.98 * min(model.boundingBox(MD2Model::STAND).getCorner(0).y, weapon.boundingBox(MD2Model::STAND).getCorner(0).y); renderDevice->beginFrame(); renderDevice->clear(true, true, true); renderDevice->pushState(); camera->setProjectionAndCameraMatrix(); beginLighting(lighting); int n = 1; if (!screenshot) { // Draw a bunch of characters for (int z = 0; z < 6; ++z) { for (int x = -2; x <= 2; ++x) { drawCharByParams(x, z, footy, n); ++n; } } } // Draw the main character { CoordinateFrame cframe(Vector3(0, -footy, -8)); if (modelTexture.size() > 0) { renderDevice->setTexture(0, modelTexture.last()); } // use global pose variable drawCharWithShadow(cframe, pose); } endLighting(); renderDevice->setObjectToWorldMatrix(CoordinateFrame()); // Ground plane (to hide parts of characters that stick through ground) renderDevice->setColor(Color3::WHITE); renderDevice->beginPrimitive(RenderDevice::QUADS); renderDevice->sendVertex(Vector3(-50, -.01, 50)); renderDevice->sendVertex(Vector3(50, -.01, 50)); renderDevice->sendVertex(Vector3(50, -.01, -50)); renderDevice->sendVertex(Vector3(-50, -.01, -50)); renderDevice->endPrimitive(); renderDevice->popState(); renderDevice->push2D(); double x = 10; double y = 10; double f = 16; int fontSize = (batchScreen) ? (22) : (30); font->draw2DString(model.name, renderDevice->getWidth()/2, renderDevice->getHeight() - 45, fontSize, Color3::BLACK, Color3::WHITE, GFont::XALIGN_CENTER); if (!screenshot) { font->draw2DString(format("%d fps", iRound(renderDevice->getFrameRate())), x, y, 20, Color3::YELLOW, Color3::BLACK); y += 30; font->draw2DString(format("%d characters", n), x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString(format("%1.1f MB", model.mainMemorySize() / 1e6), x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString(format("%1.0f Mtris/sec", renderDevice->getTriangleRate() / 1e6), x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; x = renderDevice->getWidth() - 130; y = 10; f = 12; font->draw2DString("CLICK attack", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString("SPACE jump", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString("CTRL crouch", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString("1 . . 5 taunt", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString("6 . . 8 die", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString("9 . . - pain", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString("R/T run/back", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString("E new character", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString("Z single screen", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; } renderDevice->pop2D(); renderDevice->endFrame(); }
void SDLWindow::setRelativeMousePosition(double x, double y) { SDL_WarpMouse(iRound(x), iRound(y)); }