Skip to content

Commit

Permalink
added glDisplay Python bindings for maximized/fullscreen mode
Browse files Browse the repository at this point in the history
  • Loading branch information
dusty-nv committed Feb 14, 2022
1 parent aae77a0 commit 7de695d
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 5 deletions.
76 changes: 76 additions & 0 deletions python/bindings/PyGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,78 @@ static PyObject* PyDisplay_IsClosed( PyDisplay_Object* self )
}


// IsMaximized
static PyObject* PyDisplay_IsMaximized( PyDisplay_Object* self )
{
if( !self || !self->display )
{
PyErr_SetString(PyExc_Exception, LOG_PY_UTILS "glDisplay invalid object instance");
return NULL;
}

PY_RETURN_BOOL(self->display->IsMaximized());
}


// SetMaximized
static PyObject* PyDisplay_SetMaximized( PyDisplay_Object* self, PyObject* args )
{
if( !self || !self->display )
{
PyErr_SetString(PyExc_Exception, LOG_PY_UTILS "glDisplay invalid object instance");
return NULL;
}

// parse arguments
int value = 0;

if( !PyArg_ParseTuple(args, "p", &value) )
{
PyErr_SetString(PyExc_Exception, LOG_PY_UTILS "glDisplay.SetMaximized() failed to parse args tuple");
return NULL;
}

self->display->SetMaximized(value > 0);
Py_RETURN_NONE;
}


// IsFullscreen
static PyObject* PyDisplay_IsFullscreen( PyDisplay_Object* self )
{
if( !self || !self->display )
{
PyErr_SetString(PyExc_Exception, LOG_PY_UTILS "glDisplay invalid object instance");
return NULL;
}

PY_RETURN_BOOL(self->display->IsFullscreen());
}


// SetFullscreen
static PyObject* PyDisplay_SetFullscreen( PyDisplay_Object* self, PyObject* args )
{
if( !self || !self->display )
{
PyErr_SetString(PyExc_Exception, LOG_PY_UTILS "glDisplay invalid object instance");
return NULL;
}

// parse arguments
int value = 0;

if( !PyArg_ParseTuple(args, "p", &value) )
{
PyErr_SetString(PyExc_Exception, LOG_PY_UTILS "glDisplay.SetFullscreen() failed to parse args tuple");
return NULL;
}

self->display->SetFullscreen(value > 0);
Py_RETURN_NONE;
}


// ProcessEvents
static PyObject* PyDisplay_ProcessEvents( PyDisplay_Object* self )
{
Expand Down Expand Up @@ -376,6 +448,10 @@ static PyMethodDef PyDisplay_Methods[] =
{ "GetHeight", (PyCFunction)PyDisplay_GetHeight, METH_NOARGS, "Return the height of the window (in pixels)"},
{ "IsOpen", (PyCFunction)PyDisplay_IsOpen, METH_NOARGS, "Returns true if the window is open"},
{ "IsClosed", (PyCFunction)PyDisplay_IsClosed, METH_NOARGS, "Returns true if the window has been closed"},
{ "IsMaximized", (PyCFunction)PyDisplay_IsMaximized, METH_NOARGS, "Returns true if the window is maximized"},
{ "SetMaximized", (PyCFunction)PyDisplay_SetMaximized, METH_VARARGS, "Sets the window to maximized/unmaximized based on bool argument"},
{ "IsFullscreen", (PyCFunction)PyDisplay_IsFullscreen, METH_NOARGS, "Returns true if the window is fullscreen"},
{ "SetFullscreen", (PyCFunction)PyDisplay_SetFullscreen, METH_VARARGS, "Sets the window to fullscreen mode based on bool argument"},
{ "SetBackgroundColor", (PyCFunction)PyDisplay_SetBackgroundColor, METH_VARARGS|METH_KEYWORDS, "Set the window background color"},
{ "SetTitle", (PyCFunction)PyDisplay_SetTitle, METH_VARARGS, "Set the window title string"},
{ "ProcessEvents", (PyCFunction)PyDisplay_ProcessEvents, METH_NOARGS, "Process UI events"},
Expand Down
22 changes: 17 additions & 5 deletions python/examples/gl-display-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
parser = argparse.ArgumentParser()

parser.add_argument("--title", type=str, default="Test OpenGL Display Window", help="desired title string of window")

parser.add_argument("--width", type=int, default=640, help="default width of window")
parser.add_argument("--height", type=int, default=480, help="default height of window")
parser.add_argument("--maximized", action='store_true', help="sets the window to maximized")
parser.add_argument("--fullscreen", action='store_true', help="sets the window to fullscreen")

parser.add_argument("--r", type=float, default=0.00, help="window background color (Red component, 0.0-1.0)")
parser.add_argument("--g", type=float, default=0.75, help="window background color (Green component, 0.0-1.0)")
parser.add_argument("--b", type=float, default=0.25, help="window background color (Blue component, 0.0-1.0)")
Expand All @@ -37,12 +43,18 @@
print(opt)

# create display device
display = jetson.utils.glDisplay(opt.title, opt.r, opt.g, opt.b, opt.a)

display = jetson.utils.glDisplay(opt.title, opt.width, opt.height, opt.r, opt.g, opt.b, opt.a)

if opt.maximized:
display.SetMaximized(True)

if opt.fullscreen:
display.SetFullscreen(True)

# render until user exits
while display.IsOpen():
display.BeginRender()
display.EndRender()
display.SetTitle("{:s} | {:.0f} FPS".format(opt.title, display.GetFPS()))
display.BeginRender()
display.EndRender()
display.SetTitle("{:s} | {:.0f} FPS".format(opt.title, display.GetFPS()))


0 comments on commit 7de695d

Please sign in to comment.