-
-
Save adrian-gierakowski/52a243291130a2e7eb50 to your computer and use it in GitHub Desktop.
using SFML with Skia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SFML/Graphics.hpp> | |
// include skia | |
#include "SkCanvas.h" | |
#include "SkGraphics.h" | |
#include "SkImageEncoder.h" | |
#include "SkString.h" | |
#include "SkTemplates.h" | |
#include "SkTypeface.h" | |
#include <iostream> | |
using namespace std; | |
int main(int argc, char **argv) { | |
int width = 800; | |
int height = 600; | |
// Create the main window | |
sf::RenderWindow window(sf::VideoMode(width, height), "SFML window"); | |
sf::Image image; | |
SkAutoGraphics ag; | |
//Set Text To Draw | |
SkString text("Hello Skia"); | |
SkPaint paint; | |
//Set Text ARGB Color | |
paint.setARGB(255, 255, 255, 255); | |
//Turn AntiAliasing On | |
paint.setAntiAlias(true); | |
paint.setLCDRenderText(true); | |
paint.setTypeface(SkTypeface::CreateFromName("sans-serif", SkTypeface::kNormal)); | |
//Set Text Size | |
paint.setTextSize(SkIntToScalar(20)); | |
SkBitmap bitmap; | |
bitmap.allocPixels(SkImageInfo::MakeN32Premul(width,height)); | |
//Create Canvas | |
SkCanvas canvas(bitmap); | |
canvas.drawARGB(100, 25, 25, 25); | |
//Text X, Y Position Varibles | |
int x = 80; | |
int y = 60; | |
canvas.drawText(text.c_str(), text.size(), x, y, paint); | |
//Set Style and Stroke Width | |
paint.setStyle(SkPaint::kStroke_Style); | |
paint.setStrokeWidth(3); | |
//Draw A Rectangle | |
SkRect rect; | |
paint.setARGB(255, 0, 0, 0); | |
//Left, Top, Right, Bottom | |
rect.set(50, 100, 200, 200); | |
canvas.drawRoundRect(rect, 20, 20, paint); | |
canvas.drawOval(rect, paint); | |
//Draw A Line | |
canvas.drawLine(10, 300, 300, 300, paint); | |
//Draw Circle (X, Y, Size, Paint) | |
canvas.drawCircle(100, 400, 50, paint); | |
image.create(bitmap.width(), bitmap.height(), reinterpret_cast<const sf::Uint8*>(bitmap.getPixels())); | |
// Load a sprite to display | |
sf::Texture texture; | |
if (!texture.loadFromImage(image)) | |
return EXIT_FAILURE; | |
sf::Sprite sprite(texture); | |
//sprite.SetPosition(100, 100); | |
//sprite.Resize(400, 400); | |
// Start the game loop | |
while (window.isOpen()) | |
{ | |
// Process events | |
sf::Event event; | |
while (window.pollEvent(event)) | |
{ | |
// Close window : exit | |
if (event.type== sf::Event::Closed) | |
window.close(); | |
} | |
// Clear screen | |
window.clear(); | |
window.draw(sprite); | |
// Update the window | |
window.display(); | |
} | |
return EXIT_SUCCESS; | |
} |
Does it use OpenGL for rendering ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
works with SFML 2.1, and skia checked out at commit: 47c548a