Hi everyone,
Over the past year or so I’ve been figuring things out in Panda3D and for the most part I’ve been able to do so by reading documentation, reading forum posts, and just trying things. I’ve run into an issue that I can’t seem to figure out. I could ignore it and worry about it later but I’d rather build my program one step at a time and not skip over things.
I found code somewhere that mentioned that this was a good way to switch from fullscreen to windowed or vise versa:
base.openMainWindow(**window_config)
passing in:
{'requireWindow': True,
'type': 'onscreen',
'gsg': base.win.getGsg(),
'props': self.props}
self.props is: origin=(640, 280) size=(1920, 1080) fullscreen
Recently I created a class to store the mouse which gives me quick access to 2d coordinates (not shown below) and has a way to set the texture of the pointer using parts of an egg I found in some example code. Later on I’ll probably make my own but for now that is the egg:
<CoordinateSystem> { Z-Up }
<VertexPool> poly {
<Vertex> 0 {
-0.5 0 0.5
<UV> { 0 1 }
}
<Vertex> 1 {
0.5 0 0.5
<UV> { 1 1 }
}
<Vertex> 2 {
-0.5 0 -0.5
<UV> { 0 0 }
}
<Vertex> 3 {
0.5 0 -0.5
<UV> { 1 0 }
}
}
<Group> poly {
<Polygon> {
<VertexRef> { 0 2 3 1 <Ref> { poly } }
}
}
So the issue I’m having is with combining both of these things. I set the mouse pointer to a png which is just a 16x16 black box with a single pixel white border. Then I toggle between fullscreen and windowed (or vise versa) and the pointer disappears. I’ve tried a number of things to make it display again but none have been successful.
Some of the code for my 2d mouse class:
plane is the name of the nodepath (like pixel2d). I have another class which stores them all for easy access/sorting.
resized is the function I call right after this:
base.openMainWindow(**window_config)
class TwoDMouse():
def __init__(self, plane, texture=None):
self.plane = plane
self.pointer = None
self.texture = texture
self.pointer_node = plane.attachNewNode('pointer')
self.pointer = loader.loadModel('..\\data_source\\eggs\\pointer.egg')
self.pointer.reparentTo(self.pointer_node)
base.mouseWatcherNode.setGeometry(self.pointer_node.node())
self.setTexture(texture)
self.getMouse()
def getMouse(self, event=None):
if base.mouseWatcherNode.hasMouse():
self._mouse = base.mouseWatcherNode.getMouse()
else:
base.taskMgr.doMethodLater(1, self.getMouse, 'getMouse')
def setTexture(self, texture=None):
if texture:
pointer_texture = loader.loadTexture(texture)
self.pointer.setTexture(pointer_texture)
aspectRatio = base.getAspectRatio()
height = base.win.getSbsLeftYSize()
self.pointer.setScale(32.0 / height / aspectRatio, 1.0, 32.0 / height)
self.pointer.setPos(16.0 / height / aspectRatio, 1.0, -16.0 / height)
self.hideCursor()
else:
self.pointer.clearTexture()
self.pointer.setScale(0, 0, 0)
self.showCursor()
self.texture = texture
def clearTexture(self, event=None):
self.setTexture()
def hideCursor(self):
props = WindowProperties()
props.setCursorHidden(True)
base.win.requestProperties(props)
def showCursor(self):
props = WindowProperties()
props.setCursorHidden(False)
base.win.requestProperties(props)
def resized(self, width, height):
self.pointer_node.removeNode()
self.pointer_node = self.plane.attachNewNode('pointer')
self.pointer = loader.loadModel('..\\data_source\\eggs\\pointer.egg')
self.pointer.reparentTo(self.pointer_node)
base.mouseWatcherNode.setGeometry(self.pointer_node.node())
self.setTexture(self.texture)
self.getMouse()
render2d.setClearDepthActive(True)
The code which removes the node in resized doesn’t help. Originally had it without this.
The last line which I saw somewhere doesn’t help either. My nodepath (self.plane) which has the pointer attached to it with a scale of (1, 1, 1) to match render2d doesn’t have setClearDepthActive.
The code for the mouse itself works fine. It is only after reopening the window where things go wrong.
I’ve searched with google for a number of things and can’t seem to find anything that has helped. Has anyone implemented something similar and/or knows what I am doing incorrectly or missing?
Help would be greatly appreciated.