2021SC@SDUSC Ebiten(七) 图形命令代码详解

本文介绍了Go语言的Ebiten库,用于2D游戏开发,详细解析了图形命令接口、命令队列及其相关函数,包括顶点处理、图像像素替换和图像管理等核心概念。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2021SC@SDUSC 

Go语言的简单2D游戏库-Ebiten   

 

目录

概览 

type command interface

 type commandQueue struct

theCommandQueue 

func appendVertices

func Enqueue

func Flush

type replacePixelsCommand struct

func Exec 

type disposeImageCommand struct

func Exec

type Image

func (*Image) Dump 

func (*Image) Pixels

func InitializeGraphicsDriverState

func ResetGraphicsDriverStat


概览 

包 graphicscommand 表示使用 OpenGL 的图形的低层。

主要围绕几个主要的结构体和函数展开分析

type command interface

命令表示图形命令。

是在调用图像函数(如DrawTriangles)或填充时创建的绘图命令,

命令创建后不会立即执行。已安装,创建后将排队,只有在必要时才执行。

 type commandQueue struct

commandQueue是用于图形命令的命令队列。

commands是图形命令的队列。

vertices表示OpenGL数组缓冲区中的顶点数据

nvertices表示顶点的当前长度  nvertices必须<=len(vertices)。

vertices永远不会收缩,因为重新扩展顶点缓冲区很费力。同时,这是一些float32值,而不是一些顶点  重命名或修复程序。

theCommandQueue 

var theCommandQueue = &commandQueue{}

theCommandQueue是当前进程的命令队列

func appendVertices

func appendVertices将顶点附加到队列。 

当使用着色器且没有指定的图像时,src为nil。

func Enqueue

将图形命令(而不是“绘制三角形”命令)排入队列。对于“绘制三角形”命令,使用、

EnqueueDrawTrianglesCommand。

如果dst是屏幕,将命令重新排序为最后一个。

func Flush

刷新命令队列。 

type replacePixelsCommand struct

replacePixelsCommand表示替换图像像素的命令。

func Exec 

Exec执行replacePixelsCommand。

type disposeImageCommand struct

disposeImageCommand表示处理图像的命令。 

func Exec

Exec执行disposeImageCommand

type Image

Image 表示用 OpenGL 实现的图像。

func (*Image) Dump 

转储将图像转储到指定路径。在路径中,'*' 被替换为图像的 ID。如果 blackbg 为 true,则转储图像中的任何 alpha 值将为 255。这是为了测试使用。

func (*Image) Pixels

像素返回图像的像素。发生 OpenGL 错误时,像素可能会返回 nil。 

func InitializeGraphicsDriverState

InitializeGraphicsDriverState 初始化当前图形驱动程序状态。 

func ResetGraphicsDriverStat

ResetGraphicsDriverState 重置当前图形驱动程序状态。如果图形驱动程序没有用于重置的 API,则 ResetGraphicsDriverState 不执行任何操作。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值