这年头神马都要炫,这不,我就开始研究Skia了。先上一个Skia画在opengl texture上面的圆角矩形。

以下代码:

#include <SkDevice.h> #include <SkDraw.h> #include <SkRect.h> #include <memory> #include <GL/gl.h> #include <GL/glut.h> #include <stdio.h> #include <stdlib.h> static void idle(void ); static void resize(int x , int y); static void mouseKey(int button, int state, int x , int y); static void keyFunc(unsigned char c,int x,int y); static void mouseMove(int x , int y); static void draw(void); static SkBitmap createBitmap(int x,int y) { SkBitmap bitmap; bitmap.setConfig(SkBitmap::kARGB_8888_Config, x, y); bitmap.setIsOpaque(true); bitmap.allocPixels(); std::auto_ptr<SkCanvas> psCanvas(new SkCanvas(bitmap)); SkPaint p; p.setAntiAlias(true); p.setStyle(SkPaint::kStroke_Style); p.setStrokeWidth(4); p.setColor(SkColorSetARGBInline(255,244,203,244)); psCanvas->clear(SkColorSetARGBInline(255,0,0,0)); psCanvas->drawRoundRect(SkRect::MakeXYWH(100,100,200,200),10,15,p); return bitmap; } static void generateR8G8B8FromSkBitmap(SkBitmap & aBitmap,void *& aOutBuf,size_t & aOutBufSize) { aOutBufSize = aBitmap.width() * aBitmap.height() * 3; aOutBuf = malloc(aOutBufSize); SkAutoLockPixels sAutoLock(aBitmap); uint32_t * sAddress = aBitmap.getAddr32(0,0); char * sWriter = (char * )aOutBuf; const uint32_t * sReader = sAddress; for(int y = 0 ; y < aBitmap.height() ; ++y) { for(int x = 0 ; x < aBitmap.width() ; ++ x,++sReader) { uint32_t sPixel = *sReader; const char * sPixelReader = (const char * )&sPixel; // R *sWriter = *sPixelReader; ++sWriter; ++sPixelReader; // G *sWriter = *sPixelReader; ++sWriter; ++sPixelReader; // B *sWriter = *sPixelReader; ++sWriter; ++sPixelReader; } } } GLuint getTextureFromBitmap(SkBitmap & aBitmap) { GLuint sTexture; GLenum sError; glGenTextures(1,&sTexture); glBindTexture(GL_TEXTURE_2D,sTexture); void * sBitmapContent; size_t sBitmapSize; generateR8G8B8FromSkBitmap(aBitmap,sBitmapContent,sBitmapSize); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering sError = glGetError(); printf("GL_TEXTURE_MIN_FILTER error code is %d/n",sError); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering sError = glGetError(); printf("GL_TEXTURE_MAG_FILTER error code is %d/n",sError); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP); sError = glGetError(); printf("GL_TEXTURE_WRAP_S error code is %d/n",sError); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP); sError = glGetError(); printf("GL_TEXTURE_WRAP_T error code is %d/n",sError); glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,aBitmap.width(),aBitmap.height(),0,GL_RGB,GL_UNSIGNED_BYTE,sBitmapContent); sError = glGetError(); printf("glTexImage2D error code is %d/n",sError); free(sBitmapContent); return sTexture; } int main(int argc,char ** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(800,600); //glutInitContextFlags(GLUT_FORWARD_COMPATIBLE); glutCreateWindow("test wglUseFontOutlines"); glutDisplayFunc(draw); glutIdleFunc(idle); glutReshapeFunc(resize); glutMouseFunc(mouseKey); glutMotionFunc(mouseMove); glutKeyboardFunc(keyFunc); glViewport(0,0,800,600); glClearColor(0.0f, 0.0f, 0.0f, 0.5f); glutMainLoop(); return 0; } void idle() { } void resize(int x , int y) { glViewport(0,0,x,y); } void mouseKey(int button, int state, int x , int y) { } void keyFunc(unsigned char c,int x,int y) { } void mouseMove(int x , int y) { } void draw() { glClear(GL_COLOR_BUFFER_BIT); // Set up transformation to draw the string glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(1,1,1,1,1,1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0f, 0.0f, 0.0f) ; // glPolygonMode(GL_FRONT,GL_LINE); glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glEnable(GL_TEXTURE_2D); GLint sViewportParam[4]; glGetIntegerv(GL_VIEWPORT,sViewportParam); SkBitmap sBitmap = createBitmap(sViewportParam[2],sViewportParam[3]); GLuint sTexture = getTextureFromBitmap(sBitmap); glBindTexture(GL_TEXTURE_2D,sTexture); glBegin(GL_TRIANGLE_STRIP); // glColor3f(1.0f,0.0,0.0); glTexCoord2f(0.0f,1.0f); glVertex2f(-1.0f,1.0f); // glColor3f(0.0,1.0f,0.0f); glTexCoord2f(0.0f,0.0f); glVertex2f(-1.0f,-1.0f); // glColor3f(0.0,1.0f,1.0f); glTexCoord2f(1.0f,1.0f); glVertex2f(1.0f,1.0f); // glColor3f(0.0,0.0,1.0f); glTexCoord2f(1.0f,0.0f);

接着上图:

Skia OpenGL Texture Helloworld相关推荐

  1. OpenGL Texture Coordinate Wrapping纹理坐标包装的实例

    OpenGL Texture Coordinate Wrapping纹理坐标包装 先上图,再解答. 完整主要的源代码 源代码剖析 先上图,再解答. 完整主要的源代码 #include <verm ...

  2. hwui opengl VS skia opengl VS skia vulkan?

    之前讨论过skia codec部分在o,p上的变化,比如增加了heif解码等. 其实skia在android o,p的变化不只这些. 印象最深刻的还是渲染部分 从o开始hwui渲染支持skia ope ...

  3. OpenGL Texture 纹理

    Texture 纹理 纹理是一个2D图片(也可以是一个1D和3D的纹理) 效果如下(https://github.com/curtain521517/learnOpenGL) 为了能够映射到三角形上, ...

  4. OpenGL Texture Wrap Modes纹理包裹模式的实例

    OpenGL wrapmodes纹理包裹模式 先上图,再解答. 完整主要的源代码 源代码剖析 先上图,再解答. 完整主要的源代码 #include <sb7.h> #include < ...

  5. OpenGL Texture Coordinates纹理坐标的实例

    OpenGL simpletexcoords 先上图,再解答. 完整主要的源代码 源代码剖析 先上图,再解答. 完整主要的源代码 #include <vmath.h> #include & ...

  6. Linux平台OpenGL之helloworld(十)

    OpenGL学习:learnopengl-cn.github.io 1.安装OpenGL库 # sudo apt install freeglut3-dev libxi-dev libxmu-dev ...

  7. 【Android】OpenGL ES for Android 教程1 - HelloWorld

    本教程及后续教程全部参考或者转载于:OpenGL ES Tutorial for Android 本例相当于openGL的HelloWorld程序. 先贴代码,代码中的注释比较具体了. 主Activi ...

  8. 最简单的视音频播放示例6:OpenGL播放YUV420P(通过Texture,使用Shader)

    ===================================================== 最简单的视音频播放示例系列文章列表: 最简单的视音频播放示例1:总述 最简单的视音频播放示例 ...

  9. 【OpenGL】Android 中的 skia 和 OpenGL ES

    Android Graphic : apk and Skia/OpenGL|ES Android apk 里面的画图分为2D和3D两种:2D是由Skia 来实现的,也就是我们在框架图上看到的SGL,S ...

最新文章

  1. c# oldb连接_C#使用 OleDbConnection 连接读取Excel
  2. javascript数据结构与算法---检索算法(二分查找法、计算重复次数)
  3. 机房管理系列之文件服务器管理
  4. SSIM与PSNR的计算方式
  5. 职业高中高一计算机的基本知识,职业高中计算机论文
  6. 微信小程序打开pdf文件;uni-app下载打开pdf文件;uni-app微信小程序下载打开pdf文件预览;
  7. 自动化运维脚本语言之expect实践学习(1)
  8. 东南亚跨境电商为什么推荐ERP仓储系统?
  9. KVM虚拟机安装使用教程(Ubantu)
  10. 免费的中文OCR软件
  11. mysql datetime为空不显示_将null和格式不正确的datetime值导入datetime列MySQL
  12. 【转载】关于.NET下开源及商业图像处理(PSD)组件
  13. HDU3017:Lucas定理及详解
  14. editplus3编辑器颜色修改
  15. WTL for MFC Programmers, Part V - Advanced Dialog UI Classes
  16. 完全用 GNU/Linux 工作(原版)
  17. java选择语句中switch的用法(详细介绍)
  18. UTF-8, UTF-16, UTF-16LE, UTF-16BE的区别
  19. c语言编码 企业发放德奖金,C语言 · 企业奖金发放
  20. 荣品-i.MX6Q开发板 飞思卡尔iMX6Q开发板 工业级开发板

热门文章

  1. 图像处理:边缘检测原理
  2. CAD编辑指南3:PDF转CAD以及转换后的编辑
  3. 哪些人不适合做程序员?
  4. 抖音如何起号、养号、增粉、搜索排名怎么优化
  5. 数据库having的用法介绍
  6. 宏基计算机两个DP接口,宏碁R7有什么接口?宏碁R7有几个USB接口?
  7. 报告!这群阿里工程师在偷偷养猪 1
  8. 使用VGG19训练kaggle数据state-farm-distracted-driver-detection
  9. 微型计算机的显卡,AMD发布全球首颗7nm游戏显卡,性能超越RTX 2080!
  10. isinstance()函数