我正在尝试使用类似于MS Paint的OpenGL编辑,使用面板和所有.我在哪里可以找到有关如何创建按钮和图标的材料?
PS - 我确实找到了提供此类实体的GLUI,但我不允许使用GLUT以外的任何其他内容.
源代码(如果提供)将非常有用..
由于这个问题没有指定语言(OpenGL 除外),所以我可以提供与 OpenGL 相关的信息/建议。
实际上,您需要:
void main(void) {
vec2 tile = texture2D( uTilenum, vTexCoord).xy; // Choose the specific tile to use from integer texture
vec2 spriteOffset = floor( tile * 256.0 ) * uTileSize_pix; // Find the distance to the tile corner in pixels
vec2 spriteCoord = floor( mod( vPixelCoord, uTileSize_pix ) ) + vec2( 0.5, 0.5 ); // Choose the pixel within the tile
gl_FragColor = uColor * texture2D( uTileset, ( spriteOffset + spriteCoord ) * uInverseTilesetSize_pix );
}
Run Code Online (Sandbox Code Playgroud)
<button name='button1' align='bottom left' onTouch='switchMovementMode'>
<img name='btn1img' src='74,75|90,91' width='100' height='100'></img>
</button>
<button name='button2' align='bottom left'>
<img name='btn2img' src='76,77|92,93' width='100' height='100'></img>
</button>
Run Code Online (Sandbox Code Playgroud)
Vec3[] vC = new Vec3[]{
new Vec3( -1.0f, 1.0f, 0.0f ), // top left
new Vec3( -1.0f, -1.0f, 0.0f ), // bottom left
new Vec3( 1.0f, -1.0f, 0.0f ), // bottom right
new Vec3( 1.0f, 1.0f, 0.0f ) // top right
};
ByteBuffer vertexCoordBuffer = ByteBuffer.allocateDirect( vertexCoord.length * 3 * 4 );
vertexCoordBuffer.order( ByteOrder.nativeOrder() );
for( Vec3 v : vC ){
vertexCoordBuffer.putFloat( v.x ).putFloat( v.y ).putFloat( v.z );
}
Run Code Online (Sandbox Code Playgroud)
Vec2[] tC= new Vec2[]{
new Vec2( 0.0f, 0.0f ), // top left
new Vec2( 0.0f, 1.0f ), // bottom left
new Vec2( 1.0f, 1.0f ), // bottom right
new Vec2( 1.0f, 0.0f ) // top right
};
ByteBuffer texCoordBuffer = ByteBuffer.allocateDirect( texCoord.length * 2 * 4 );
texCoordBuffer.order( ByteOrder.nativeOrder() );
for( Vec2 c : Tc ){
texCoordBuffer.putFloat( c.x ).putFloat( c.y );
}
Run Code Online (Sandbox Code Playgroud)
int[] drawOrder = new int[]{
0, 1, 2, 0, 2, 3
};
ByteBuffer dlb = ByteBuffer.allocateDirect( drawOrder.length * 4 );
dlb.order( ByteOrder.nativeOrder() );
drawListBuffer = dlb.asIntBuffer();
drawListBuffer.put( drawOrder );
Run Code Online (Sandbox Code Playgroud)
glDrawElements( GLES30.GL_TRIANGLES, drawOrder.length, GLES30.GL_UNSIGNED_INT, drawListBuffer );
Run Code Online (Sandbox Code Playgroud)