Irrlicht Engine: Window pops up and disappears instantly - irrlicht

I wanted to create a simple IrrlichtDevice with IrrlichtEngine, but when I start the application, the window just appears on the screen and then instantly disappears.
My code looks like following:
int main()
{
IrrlichtDevice *device =
createDevice( video::EDT_DIRECT3D9, dimension2d<u32>(640, 480), 16,
false, false, false, 0);
}
(code copied from the HelloWorld tutorial of the documentation)

Try
int main()
{
IrrlichtDevice *device =
createDevice( video::EDT_DIRECT3D9, dimension2d<u32>(640, 480), 16,
false, false, false, 0);
while( device->run() )
{ device->getVideoDriver()->beginScene( true, true, video::SColor( 50, 50, 50, 50) );
device->getVideoDriver()->endScene();
}
}

You have no looping system in place. After you create the device the function immediately ends and everything is cleaned up.
bob2 has the correct answer, I would suggest that you practice making simple c++ applications before diving in the deep end.

Related

JXA set window bounds weird issue

script1.js:
function run() {
const chromeApp = Application('Google Chrome');
const window = chromeApp.windows[0];
console.log(window.name());
window.bounds = {
x: 0,
y: 0,
width: 500,
height: 500,
};
chromeApp.activate();
}
Run:
osascript -l JavaScript script1.js
And it works
script2.js:
function run() {
const systemEvents = Application('System Events');
const ap = systemEvents.processes().find(ap => ap.name() === 'Google Chrome');
console.log(ap.name());
const window = ap.windows[0];
console.log(window.name());
window.bounds = {
x: 0,
y: 0,
width: 500,
height: 500,
};
}
Run:
osascript -l JavaScript script1.js
It does NOT work:
script2.js: execution error: Error: Error: Can't set that. (-10006)
But I really need to get script2.js work. Because in my real application, I don't know the application name in advance and I need to fetch the process dynamically base on user interaction. Because I don't know application name, I cannot use script1.js.
Any input is appreciate!
function run() {
const systemEvents = Application('System Events');
const p = systemEvents.processes().find(ap => ap.frontmost() === true);
const ap = Application (p.bundleIdentifier());
const window = ap.windows[0];
window.bounds = {
x: 0,
y: 0,
width: 500,
height: 500,
};
}
It’s years since I’ve had the displeasure of using GUI Scripting so didn’t immediately spot the real problem.
The real problem is that System Events is a bloated badly designed mess that shoehorns a dozen libraries’ worth of functionality into one #BigBallOfMud.
SE includes Cocoa Scripting’s Standard Suite window class definition, including a standard bounds property, but doesn’t actually implement it (since SE has no windows of its own). So while SE’s dictionary claims windows elements have a bounds property, trying to get/set that property throws an error. It is very confusing.
Therefore, ignore the window class definition in SE’s Standard Suite, and only look at the window class definition in its Process Suite (aka GUI Scripting). It doesn’t have a bounds property; instead it has separate position and size properties:
position (list of number or missing value) : the position of the window
size (list of number or missing value) : the size of the window
Here is code that works:
tell application "System Events"
set ap to first process whose name is "Firefox"
set win to window 1 of ap
-- set bounds of win to {100, 100, 600, 600} -- this doesn't actually work
set position of win to {100, 100}
set size of win to {500, 500}
end tell
In other words, just because an app’s dictionary says it supports something doesn’t mean it actually does. Trying to figure out an app’s brokenness while also wrestling with JXA’s brokenness is at best a Sisyphean’ exercise.
Figure out how you get your code working in AppleScript first; if it doesn’t work there then you know it’s the app that’s the problem. If you still want to use JXA, then you can attempt to port your working code to that afterwards (although generally I don’t recommend wasting time on JXA as it’s crippled and abandoned, and the whole AppleScript stack is slowly dying anyway).
Inspired by Robert's answer, I found that the following works:
function run() {
const systemEvents = Application('System Events');
const p = systemEvents.processes().find(ap => ap.name() === 'Google Chrome');
console.log(p.name());
const app = Application(p.name());
const window = app.windows[0];
window.bounds = {
x: 0,
y: 0,
width: 500,
height: 500,
};
app.activate();
}
So I can convert a Process into Application by name: const app = Application(p.name()); Then script2.js become script1.js.
But it doesn't always work. For example, the following doesn't work:
function run() {
const systemEvents = Application('System Events');
const p = systemEvents.processes().find(ap => ap.frontmost() === true);
console.log(p.name());
const app = Application(p.name());
const window = app.windows[0];
window.bounds = {
x: 0,
y: 0,
width: 500,
height: 500,
};
app.activate();
}
If the frontmost application is Visual Studio Code. Because the process name will be "Electron" and convert process to application will be wrong.
I'd like to find a way to convert process to application by ID. I am still investigating and I will post updates later.
Update: please check the accepted answer.
You can set the position and size to a two-dimensional array. Because Application("Name of App") doesn't always seem to work, it's best to go through System Events.
let sys = Application("System Events")
let app = sys.applicationProcesses
.whose({ name: "AppYouWant"})[0]
app[0].windows[0].size = [200, 200]
app[0].windows[0].position = [200, 200]

GO GUI help (walk package)

I am making a GUI for my app, using package lxn/walk.
I'm trying to figure out how to place elements by pixels. My code is like this:
package main
import (
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
)
var edit *walk.Label
func main() {
MainWindow{
Title: "FetchTest",
MinSize: Size{600, 400},
Layout: VBox{},
Children: []Widget{
Label{
AssignTo: &edit,
Text: "Hello",
},
PushButton{
Text: "GET DATA",
OnClicked: func() {
},
},
},
}.Run()
edit.SetBounds(walk.Rectangle{10, 5, 50, 50})
}
But this doesn't work since the code that sets the position of label is not executing.
Where to use edit.SetBounds(walk.Rectangle{10, 5, 50, 50} so the element is shown at the given coordinates?
I'm not familiar with walk, but maybe MainWindow.Run() only returns when the window is closed? You could try the approach used in the walk "filebrowser" example: call Create to set up the window, do any additional initialization, and then call Run.

Loading and displaying an image on the canvas using scala.js

I just started messing with scala.js and got stuck pretty early. I have no scala experience so I probably overlooked something simple. I try to display an image on the canvas. I tried:
var image:HTMLImageElement = new HTMLImageElement()
image.src = "pathToSource"
image.onload = { () =>
ctx.drawImage(image, 0, 0, 200, 200) //ctx is the canvas rendering context
}
The problem with this code is that onload doesn't seem to exist, even though I can find it here: https://github.com/scala-js/scala-js-dom/blob/master/src/main/scala/org/scalajs/dom/raw/Html.scala#L1333
I also tried a few other methods like onloaddata but I cant figure out what the compiler wants from me:
var image:dom.raw.HTMLImageElement = new HTMLImageElement()
image.src = "/img/image.png"
image.onloadeddata = new js.Function1[Event, _]{
def apply(v1: Event):Unit={
ctx.drawImage(image,0,0,200,200)
}
}
Anyone knows how to load and display an image with scala js?
Thanks in advance!
You have to create the image with dom.document.createElement("img")
and then use onload event on the created image, here is a working example:
val ctx = canvas.getContext("2d")
.asInstanceOf[dom.CanvasRenderingContext2D]
var image = dom.document.createElement("img").asInstanceOf[HTMLImageElement]
image.src = "/img/image.gif"
image.onload = (e: dom.Event) => {
ctx.drawImage(image, 0, 0, 525, 600, 0, 0, 525, 600)
}
Which version of org.scalajs.dom are you using? It looks like onload was added quite recently, in version 0.8.2. That might be the source of your confusion. (I'm on version 0.8.0, and get the same error.)
For reference, the idiomatic Scala syntax for something like this would usually be something like:
image.onloadeddata = { evt:Event =>
ctx.drawImage(image, 0, 0, 200, 200) //ctx is the canvas rendering context
}
or possibly (in some cases, if there is ambiguity):
image.onloadeddata = { evt:Event =>
ctx.drawImage(image, 0, 0, 200, 200) //ctx is the canvas rendering context
}:js.Function1[Event, _]
You're missing an = operator right after .onload.

Is vertex attrubute pointer persistent in OpenGL ES?

Imagine scenario when have two GLSL programms A and B that are called one after another.
If to set uniform variable of the program A it's value stays the same and requires no initialization before every draw call of the program. So it can be considered as a "member" of the program (in terms of OOP).
But what about attribute values or when vertex attribute is set as pointer?
You tagged your question as OpenGL ES and WebGL. In both of those attributes are global. Their state is not connected to any GLSL programs.
You can think of it kind of like this
glState = {
attributes: [
{ enabled: false, type: gl.FLOAT, size: 4, stride:0, offset: 0, buffer, null, },
{ enabled: false, type: gl.FLOAT, size: 4, stride:0, offset: 0, buffer, null, },
{ enabled: false, type: gl.FLOAT, size: 4, stride:0, offset: 0, buffer, null, },
{ enabled: false, type: gl.FLOAT, size: 4, stride:0, offset: 0, buffer, null, },
...
]
};
gl.enableVertexAttribArray, gl.disableVertexAttribArray, and gl.vertexAtrribPointer effect that global attribute state. More details here.
There is an extension on ES 2.0 and WebGL for Vertex Array Objects. That extensions allows the combine state of all attributes to be set and stored on Vertex Array Objects or "VAO"s. There is still global state as well which for the most part can be considered the default VAO.
You can consider that to work like this
glState = {
defaultVAO = {
attributes: [
{ enabled: false, type: gl.FLOAT, size: 4, stride:0, offset: 0, buffer, null, },
{ enabled: false, type: gl.FLOAT, size: 4, stride:0, offset: 0, buffer, null, },
{ enabled: false, type: gl.FLOAT, size: 4, stride:0, offset: 0, buffer, null, },
{ enabled: false, type: gl.FLOAT, size: 4, stride:0, offset: 0, buffer, null, },
...
]
},
currentVAO = defaultVAO
};
Now gl.enableVertexAttribArray, gl.disableVertexAttribArray, and gl.vertexAtrribPointer affect the attributes of currentVAO in the above example. Calling createVertexArrayOES creates a new VAO. Calling bindVertexArrayOES sets currentVAO in the above pseudo code to your new VAO. Calling bindVertexArrayOES with null sets currentVAO back to the default one.
In ES 3.0 VAOs are always available (in other words they are no longer an extension, they're part of the basic set of features.)
NOTE: VAOs are easy to emulate. There's an emulation library here so you can use VAOs anywhere in WebGL. If they are supported the emulation library will use the native ones. If they aren't it will emulate them.
In OpenGL prior to 3.2 Core, attribute bindings are handled by the underlying state machine and are global. This means that they stay the same as long as noone modifies them.
Beginning with OpenGL 3.2 Core Profile these attribute settings are no longer global, but get stored in a VAO (Vertex Array Object). Again each VAO updates it's state when it is active, and stores the last know state when it gets deactivated.
In both cases, attribute bindings do not have any connection to the currently bound shader.

Switch between Jump and Run animation Andengine

I want switch between Run and Jump animations, but i have some problems :
If the Player run and i tap on the screen, the Player start Jumping (one time), and the Jumpanimation starts but don´t end , so the player is running with the Jumpanimation.
Do you know where my fault is?
My code :
// Runanimation + Player Run
public void setRunning()
{
canRun = true;
final long[] PLAYER_ANIMATE = new long[] { 100, 100, 100,};
animate(PLAYER_ANIMATE, 0, 2, true);
}
// Jumpanimation + Player Jump
public void jump()
{
if (footContacts < 1)
{
return;
}
body.setLinearVelocity(new Vector2(body.getLinearVelocity().x, 10));
final long[] PLAYER_JUMP_ANIMATE = new long[] { 100, 100, 100, 100, 100, 100};
animate(PLAYER_JUMP_ANIMATE, 0, 5,true);
}
Thx Seref
You are animating with loop boolean set to true, which means its keep looping animation. You should have some kinds of flags (booleans) like jumping and running, so inside set running method you should check if jumping equals true, and if so, stopAnimation() and animate using different frames (in this case running)

Resources