@@ -32,6 +32,7 @@ class RaylibJs {
32
32
this . currentPressedKeyState = new Set ( ) ;
33
33
this . currentMouseWheelMoveState = 0 ;
34
34
this . currentMousePosition = { x : 0 , y : 0 } ;
35
+ this . images = [ ] ;
35
36
this . quit = false ;
36
37
}
37
38
@@ -235,6 +236,36 @@ class RaylibJs {
235
236
return this . ctx . measureText ( text ) . width ;
236
237
}
237
238
239
+ // RLAPI Texture2D LoadTexture(const char *fileName);
240
+ async LoadTexture ( result_ptr , filename_ptr ) {
241
+ const buffer = this . wasm . instance . exports . memory . buffer ;
242
+ const filename = cstr_by_ptr ( buffer , filename_ptr ) ;
243
+
244
+ var result = new Uint32Array ( buffer , result_ptr , 5 )
245
+ var img = new Image ( ) ;
246
+ img . src = filename ;
247
+ this . images . push ( img ) ;
248
+
249
+ result [ 0 ] = this . images . indexOf ( img ) ;
250
+ result [ 1 ] = 256 ; // width
251
+ result [ 2 ] = 256 ; // height
252
+ result [ 3 ] = 1 ; // mipmaps
253
+ result [ 4 ] = 7 ; // format PIXELFORMAT_UNCOMPRESSED_R8G8B8A8
254
+
255
+ return result ;
256
+ }
257
+
258
+ // RLAPI void DrawTexture(Texture2D texture, int posX, int posY, Color tint);
259
+ DrawTexture ( texture_ptr , posX , posY , color_ptr ) {
260
+ const buffer = this . wasm . instance . exports . memory . buffer ;
261
+ const [ id , width , height , mipmaps , format ] = new Uint32Array ( buffer , texture_ptr , 5 ) ;
262
+ // const tint = getColorFromMemory(buffer, color_ptr);
263
+
264
+ if ( this . images [ id ] ) {
265
+ this . ctx . drawImage ( this . images [ id ] , posX , posY ) ;
266
+ }
267
+ }
268
+
238
269
raylib_js_set_entry ( entry ) {
239
270
this . entryFunction = this . wasm . instance . exports . __indirect_function_table . get ( entry ) ;
240
271
}
0 commit comments