Skip to content

Commit

Permalink
android: Added compat/glconsole.h to (rather hackily) support GLConso…
Browse files Browse the repository at this point in the history
…le, forcing it to use Pangolins fonts and ignoring glut calls.
  • Loading branch information
stevenlovegrove committed Jul 7, 2013
1 parent fa9fdf2 commit 05fb69b
Show file tree
Hide file tree
Showing 10 changed files with 214 additions and 56 deletions.
18 changes: 16 additions & 2 deletions examples/HelloPangolin/main.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#include <pangolin/pangolin.h>
#include <pangolin/glfont.h>
#include <pangolin/image_load.h>

int main( int /*argc*/, char** /*argv*/ )
int main( int argc, char** argv )
{
pangolin::CreateWindowAndBind("Main",640,480);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

// Define Projection and initial ModelView matrix
pangolin::OpenGlRenderState s_cam(
Expand All @@ -14,9 +18,13 @@ int main( int /*argc*/, char** /*argv*/ )
// Create Interactive View in window
pangolin::Handler3D handler(s_cam);
pangolin::View& d_cam = pangolin::CreateDisplay()
.SetBounds(0.0, 1.0, 0.0, 1.0, -640.0f/480.0f)
.SetBounds(0.0, 1.0, 0.0, 1.0, 640.0f/480.0f)
.SetHandler(&handler);

pangolin::GlFont font;

pangolin::GlText test = font.Text("Testing my magnificance...");

while( !pangolin::ShouldQuit() )
{
// Clear screen and activate view to render into
Expand All @@ -26,6 +34,12 @@ int main( int /*argc*/, char** /*argv*/ )
// Render OpenGL Teapot
glColor3f(1.0,1.0,1.0);
pangolin::glDrawColouredCube();

glColor4f(1.0f,1.0f,1.0f,1.0f);
test.Draw(2,2,2);

pangolin::DisplayBase().ActivatePixelOrthographic();
test.Draw(100,100);

// Swap frames and Process Events
pangolin::FinishFrame();
Expand Down
42 changes: 20 additions & 22 deletions examples/SimpleDisplayImage/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <limits>
#include <iostream>
#include <pangolin/pangolin.h>
#include <pangolin/image_load.h>

using namespace std;
using namespace pangolin;
Expand All @@ -13,8 +14,13 @@ void setImageData(unsigned char * imageArray, int size){

int main( int /*argc*/, char* argv[] )
{
std::string filename = "/Users/slovegrove/Documents/Drawing/Cool illustrations CFSL/31_32_clement_fait_pipi_est.jpg";
pangolin::TypedImage img = pangolin::LoadImage(filename);

// Create OpenGL window in single line thanks to GLUT
CreateWindowAndBind("Main",640,480);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

// 3D Mouse handler requires depth testing to be enabled
glEnable(GL_DEPTH_TEST);
Expand All @@ -24,52 +30,44 @@ int main( int /*argc*/, char* argv[] )
ModelViewLookAt(-1,1,-1, 0,0,0, AxisY)
);

// Aspect ratio allows us to constrain width and height whilst fitting within specified
// bounds. A positive aspect ratio makes a view 'shrink to fit' (introducing empty bars),
// whilst a negative ratio makes the view 'grow to fit' (cropping the view).
View& d_cam = Display("cam")
.SetBounds(0,1,0,1,-640/480.0)
.SetHandler(new Handler3D(s_cam));

// This view will take up no more than a third of the windows width or height, and it
// will have a fixed aspect ratio to match the image that it will display. When fitting
// within the specified bounds, push to the top-left (as specified by SetLock).
View& d_image = Display("image")
.SetBounds(2/3.0,1.0,0,1/3.0,640.0/480)
.SetAspect((float)img.w / (float)img.h)
.SetLock(LockLeft,LockTop);

cout << "Resize the window to experiment with SetBounds, SetLock and SetAspect." << endl;
cout << "Notice that the teapots aspect is maintained even though it covers the whole screen." << endl;

const int width = 64;
const int height = 48;
// const int width = 64;
// const int height = 48;

unsigned char* imageArray = new unsigned char[3*width*height];
GlTexture imageTexture(width,height,GL_RGB,false,0,GL_RGB,GL_UNSIGNED_BYTE);
// unsigned char* imageArray = new unsigned char[3*width*height];
// GlTexture imageTexture(width,height,GL_RGB,false,0,GL_RGB,GL_UNSIGNED_BYTE);

GlTexture imageTexture(img.w, img.h, GL_RGB,false,0,GL_RGB,GL_UNSIGNED_BYTE);
imageTexture.Upload(img.ptr, GL_RGB, GL_UNSIGNED_BYTE);

// Default hooks for exiting (Esc) and fullscreen (tab).
while(!pangolin::ShouldQuit())
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

d_cam.Activate(s_cam);

glColor3f(1.0,1.0,1.0);
glDrawColouredCube();

//Set some random image data and upload to GPU
setImageData(imageArray,3*width*height);
imageTexture.Upload(imageArray,GL_RGB,GL_UNSIGNED_BYTE);
// //Set some random image data and upload to GPU
// setImageData(imageArray,3*width*height);
// imageTexture.Upload(imageArray,GL_RGB,GL_UNSIGNED_BYTE);

//display the image
d_image.Activate();
glColor3f(1.0,1.0,1.0);
imageTexture.RenderToViewport();
imageTexture.RenderToViewportFlipY();

pangolin::FinishFrame();
}

delete[] imageArray;
img.Dealloc();
// delete[] imageArray;

return 0;
}
27 changes: 27 additions & 0 deletions include/pangolin/compat/boostd.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2013 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef PANGOLIN_COMPAT_BOOSTD_H
#define PANGOLIN_COMPAT_BOOSTD_H

Expand Down
70 changes: 70 additions & 0 deletions include/pangolin/compat/glconsole.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2013 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef PANGOLIN_COMPAT_GLCONSOLE_H
#define PANGOLIN_COMPAT_GLCONSOLE_H

// If we don't have GLUT, coerce GLConsole to work with out own font rendering.
#ifdef HAVE_GLES
#include <pangolin/glinclude.h>
#include <pangolin/glfont.h>

// Define our own GLFont class, preventing GLConsoles from being included.
#define __GL_FONT_H__

class GLFont
{
public:
void glPrintf(int x, int y, const char *fmt, ...)
{
pangolin::GlFont::I().Text(fmt).DrawWindow(x,y);
}
void glPrintf(int x, int y, const std::string fmt, ...){ glPrintf(x,y, fmt.c_str()); }
void glPrintfFast(int x, int y, const char *fmt, ...) { glPrintf(x,y,fmt); }
void glPrintfFast(int x, int y, const std::string fmt, ...){ glPrintfFast(x,y, fmt.c_str()); }
unsigned int CharHeight() { return 10; }
unsigned int CharWidth() { return 10; }
};
#define glPushAttrib(x)
#define glPopAttrib(x)
#define glutGetModifiers(x) (0)
#define GLUT_ACTIVE_SHIFT 0
#define GLUT_ACTIVE_CTRL 1
#define GLUT_ACTIVE_ALT 2
#define GLUT_KEY_UP 3
#define GLUT_KEY_DOWN 4
#define GLUT_KEY_LEFT 5
#define GLUT_KEY_RIGHT 6
#define GLUT_KEY_PAGE_UP 7
#define GLUT_KEY_PAGE_DOWN 8
#define GLUT_KEY_HOME 9
#define GLUT_KEY_END 10
#endif // HAVE_GLES

#include <GLConsole/GLConsole.h>

#endif // PANGOLIN_COMPAT_GLCONSOLE_H
6 changes: 3 additions & 3 deletions include/pangolin/compat/glutbitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef PANGOLIN_GLUT_BITMAP_H
#define PANGOLIN_GLUT_BITMAP_H
#ifndef PANGOLIN_COMPAT_GLUT_BITMAP_H
#define PANGOLIN_COMPAT_GLUT_BITMAP_H
#ifndef HAVE_GLUT

#include <pangolin/glfont.h>
Expand Down Expand Up @@ -88,4 +88,4 @@ inline int glutBitmapLength(void *font, const unsigned char *str)
#define GLUT_BITMAP_HELVETICA_12 0;

#endif // HAVE_GLUT
#endif // PANGOLIN_GLUT_BITMAP_H
#endif // PANGOLIN_COMPAT_GLUT_BITMAP_H
27 changes: 27 additions & 0 deletions include/pangolin/compat/memory.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2013 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef PANGOLIN_COMPAT_MEMORY_H
#define PANGOLIN_COMPAT_MEMORY_H

Expand Down
2 changes: 1 addition & 1 deletion include/pangolin/display_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#endif // BUILD_PANGOLIN_VIDEO

#ifdef HAVE_CVARS
#include <GLConsole/GLConsole.h>
#include <pangolin/compat/glconsole.h>
#endif // HAVE_CVARS

namespace pangolin
Expand Down
12 changes: 6 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ endif()

#######################################################
## Find optional dependencies
find_package(CVARS 2.3 QUIET)
if(CVARS_FOUND)
set(HAVE_CVARS 1)
list(APPEND USER_INC ${CVARS_INCLUDE_DIR} )
list(APPEND LINK_LIBS ${CVARS_LIBRARIES} )
endif()

## Don't even try to find these things on android
if(NOT ANDROID)
find_package(CVARS 2.3 QUIET)
if(CVARS_FOUND)
set(HAVE_CVARS 1)
list(APPEND USER_INC ${CVARS_INCLUDE_DIR} )
list(APPEND LINK_LIBS ${CVARS_LIBRARIES} )
endif()

find_package(CUDA QUIET)
if(CUDA_FOUND)
Expand Down
3 changes: 3 additions & 0 deletions src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ __thread PangolinGl* context = 0;
PangolinGl::PangolinGl()
: quit(false), mouse_state(0), activeDisplay(0)
{
#if defined(HAVE_CVARS) && defined(HAVE_GLES)
console.m_fOverlayPercent = 0.5;
#endif
}

PangolinGl::~PangolinGl()
Expand Down
Loading

0 comments on commit 05fb69b

Please sign in to comment.