1 Screenshot
2 Source code
/*
* Polygon.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
#include <sol/opengl/OpenGLMainView.h>
#include <sol/opengl/OpenGLView.h>
#include <sol/opengl/OpenGLGC.h>
#include <sol/opengl/OpenGLLight.h>
#include <sol/opengl/OpenGLMaterial.h>
namespace SOL {
class MainView :public OpenGLMainView {
private:
//Inner class starts
class SimpleView: public OpenGLView {
private:
SmartPtr<OpenGLGC> gc;
public:
//This method will be called from an expose callback of OpenGLView.
virtual void display()
{
if (gc) {
const GLfloat lightPosition[] = { 5.0 , 0.0 , -8.0 , 1.0 };
const GLfloat lightColor[] = { 0.5 , 1 , 0.5 , 1 };
const GLfloat materialColor[] = { 0.2 , 0.6 , 0.2 , 1};
OpenGLLight light(GL_LIGHT0);
light.position(lightPosition);
light.diffuse(lightColor);
light.enable();
OpenGLMaterial material(GL_FRONT_AND_BACK );
material.diffuse(materialColor);
gc -> clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gc -> begin(GL_POLYGON);
gc -> normal(3.0 , 0.0 , -2.0);
gc -> vertex(0.0 , -0.9 , -2.0);
gc -> vertex(3.0 , -0.9 , -7.0);
gc -> vertex(0.0 , 0.9 , -2.0 );
gc -> normal(-3.0 , 0.0 , -2.0);
gc -> vertex(0.0 , -0.9 , -2.0);
gc -> vertex(-3.0, -0.9 , -7.0);
gc -> vertex(0.0, 0.9 , -2.0);
gc -> end();
}
}
//This method will be called from a structureNotiy event handler of OpenGLView.
virtual void resize(int widht, int height)
{
//Write your own resize procedure.
}
//This method will be called from a mapNotify event handler of OpenGLView.
virtual void initialize()
{
gc = new OpenGLGC();
gc -> enable(GL_LIGHTING);
gc -> matrixMode(GL_PROJECTION);
gc -> loadIdentity();
gc -> frustum(1, -1, -1, 1, 2, 10);
}
public:
SimpleView(View* parent, const char* name, Args& args)
:OpenGLView(parent, name, args)
{
}
~SimpleView()
{
}
};
//Inner class ends
private:
SmartPtr<SimpleView> view;
long size(Event& event)
{
int width = 0;
int height = 0;
event.getSize(width, height);
if (view) {
view -> reshape(0, 0, width, height);
view -> postResizeRequest(width, height);
}
return 0L;
}
public:
MainView(Application& applet, const char* name, Args& args)
:OpenGLMainView(applet, name, args)
{
Args ar;
view = new SimpleView(this, "", ar);
}
~MainView()
{
}
};
}
//
void Main(int argc, char** argv)
{
try {
const char* name = appName(argv[0]);
Application applet(name, argc, argv);
Args args;
args.set(XmNwidth, 400);
args.set(XmNheight, 300);
MainView view(applet, name, args);
view.realize();
applet.run();
} catch (Exception& ex) {
caught(ex);
}
}
Last modified: 25 Feb 2017
Copyright (c) 2017 Antillia.com ALL RIGHTS RESERVED.