Want to learn graphics using Skia on Ubuntu -
Want to learn graphics using Skia on Ubuntu -
i want larn graphics programming, , want utilize skia library. how begin on ubuntu?
use r1236 version. newer versions of skia have issues on linux.
svn checkout http://skia.googlecode.com/svn/trunk -r1236 // new url: svn checkout http://skia.googlecode.com/svn/trunk_no_commit -r1236 cd trunk
skia has font paths hard coded, want alter that.
edit src/ports/skfonthost_linux.cpp
search "sk_font_file_prefix"
change "/usr/share/fonts/truetype/msttcorefonts/" "/usr/share/fonts/ttf/"
./gyp/gyp_skia create
you should have libskia.a.
#include "skcanvas.h" #include "skgraphics.h" #include "skimageencoder.h" #include "skstring.h" #include "sktemplates.h" #include "sktypeface.h" // g++ main.cpp -wl,-rpath,./ -l. -lskia -iinclude/core -iinclude/config -iinclude/images -lpthread -lfreetype -lpng -o main int main (int argc, char * const argv[]) { // skautographics ag; //output filename skstring path("skhello.png"); //set text draw skstring text("hydra v0.0.1a"); 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(40)); //set image width & height int width = 500; int height = 600; skbitmap bitmap; bitmap.setconfig(skbitmap::kargb_8888_config, width, height); bitmap.allocpixels(); //create canvas skcanvas canvas(bitmap); canvas.drawargb(255, 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 , stroke width paint.setstyle(skpaint::kstroke_style); paint.setstrokewidth(3); //draw rectangle skrect rect; paint.setargb(255, 255, 255, 255); //left, top, right, bottom rect.set(50, 100, 200, 200); canvas.drawroundrect(rect, 20, 20, paint); canvas.drawoval(rect, paint); //draw line canvas.drawline(10, 300, 300, 300, paint); //draw circle (x, y, size, paint) canvas.drawcircle(100, 400, 50, paint); //same image (file, bitmap, image_type, quality) skimageencoder::encodefile(path.c_str(), bitmap, skimageencoder::kpng_type, 0); homecoming 0; }
here sfml2 , skia example:
#include <sfml/graphics.hpp> #include "skcanvas.h" #include "skgraphics.h" #include "skimageencoder.h" #include "skstring.h" #include "sktemplates.h" #include "sktypeface.h" #include <iostream> // g++ main.cpp -wl,-rpath,./ -l. -lskia -iinclude/core -iinclude/config -iinclude/images -lpthread -lfreetype -lpng -lsfml-window -lsfml-graphics -lsfml-system using namespace std; int main(int argc, char **argv) { int width = 800; int height = 600; // create main window sf::renderwindow window(sf::videomode(width, height), "sfml window"); sf::image image; skautographics ag; //set text draw skstring text("hydra skia v0.0.1a"); 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.setconfig(skbitmap::kargb_8888_config, width / 2, height); bitmap.allocpixels(); //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 , stroke width paint.setstyle(skpaint::kstroke_style); paint.setstrokewidth(3); //draw 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 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 sprite display sf::texture texture; if (!texture.loadfromimage(image)) homecoming exit_failure; sf::sprite sprite(texture); //sprite.setposition(100, 100); //sprite.resize(400, 400); // load sprite display sf::texture tex; if (!tex.loadfromfile("background.jpg")) homecoming exit_failure; sf::sprite texs(tex); // start game loop while (window.isopened()) { // 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(texs); window.draw(sprite); // update window window.display(); } homecoming exit_success; }
skia
Comments
Post a Comment