Jump to content

[SOLVED] How to show the image in the canvas


photo

Recommended Posts

Hi.

Tell me, how can I show image to the canvas?



Gui gui = engine.getGui();
WidgetCanvas canvas = new WidgetCanvas(gui);
gui.addChild(canvas);
canvas.setWidth(512);
canvas.setHeight(512);
canvas.setTexture("D:/Textures/sprite.png"); // I do not see
Image im = new Image("D:/Textures/sprite.png"); // I do not see
canvas.setImage(im);


Link to comment
Thank you. In the project I have taken from the texture folder data.

Here, I have simplified the example to make it easier to read.

But this is still not the solution = (
Link to comment

vita_de,

 

Please, use the WidgetSprite if you want to draw 2D image on screen. WidgetCanvas is designed to draw polygons, lines and text.

But, if you still want to draw 2D image in WidgetCanvas, here is the example code:

class Canvas {
	
	Gui gui;
	
	WidgetCanvas canvas;
	
	Canvas() {
		
		gui = engine.getGui();
		
		// canvas
		canvas = new WidgetCanvas(gui);
		
		canvas.setHeight(512);
		canvas.setWidth(512);
		
		canvas.setTexture("sprite_01.png");
		create_quad(0,vec3(512.0f,0.0f,0.0f),vec3(0.0f,0.0f,0.0f),vec3(0.0f,512.0f,10.0f),vec3(512.0f,512.0f,10.0f),vec3(1.0f,0.0f,1.0f),vec3(0.0f,0.0f,1.0f),vec3(0.0f,1.0f,1.0f),vec3(1.0f,1.0f,1.0f));
	
		gui.addChild(canvas);
	}
	~Canvas() {
		delete canvas;
	}
	
	//
	int create_quad(int order,vec3 p1,vec3 p2,vec3 p3,vec3 p4,vec3 tex_p1,vec3 tex_p2,vec3 tex_p3,vec3 tex_p4) {
		int polygon = canvas.addPolygon(order);
		canvas.addPolygonPoint(polygon,p1);
		canvas.setPolygonTexCoord(polygon,tex_p1);
		canvas.addPolygonPoint(polygon,p2);
		canvas.setPolygonTexCoord(polygon,tex_p2);
		canvas.addPolygonPoint(polygon,p3);
		canvas.setPolygonTexCoord(polygon,tex_p3);
		canvas.addPolygonPoint(polygon,p4);
		canvas.setPolygonTexCoord(polygon,tex_p4);
		return polygon;
	}
	
};

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment
  • 1 month later...
×
×
  • Create New...