chunkstream version fixedleaselication
git-svn-id: svn://db.shs.com.ru/libs@3 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -4,7 +4,7 @@ find_package(Qt4 REQUIRED)
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${QT_INCLUDES})
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wall")
|
||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
|
||||
add_definitions(-DGL_GLEXT_PROTOTYPES)
|
||||
@@ -12,7 +12,7 @@ set(LIBS ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} qad_wid
|
||||
if (${WIN32})
|
||||
list(APPEND LIBS opengl32 glu32)
|
||||
else (${WIN32})
|
||||
list(APPEND LIBS GL GLU)
|
||||
list(APPEND LIBS GL GLU glut GLEW)
|
||||
endif (${WIN32})
|
||||
|
||||
file(GLOB MOCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h")
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#elif defined(__APPLE__) || defined(__APPLE_CC__)
|
||||
#define GL_GLEXT_LEGACY
|
||||
#include <OpenGL/gl.h>
|
||||
|
||||
@@ -81,7 +81,9 @@ void GLFramebuffer::bind() {
|
||||
if (fbo == 0) return;
|
||||
glFlush();
|
||||
glGetIntegerv(GL_VIEWPORT, prev_view);
|
||||
//glClearError();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
//qDebug() << QString::number(glGetError(), 16);
|
||||
QVector<GLenum> buffers;
|
||||
for (int i = 0; i < colors.size(); ++i)
|
||||
buffers << GL_COLOR_ATTACHMENT0 + i;
|
||||
|
||||
@@ -32,6 +32,9 @@ public:
|
||||
GLenum colorFormat() const {return color_format;}
|
||||
GLuint depthTexture() const {return tex_d;}
|
||||
GLenum target() const {return target_;}
|
||||
int width() const {return wid;}
|
||||
int height() const {return hei;}
|
||||
QSize size() const {return QSize(wid, hei);}
|
||||
|
||||
void resize(int width, int height);
|
||||
void bind();
|
||||
|
||||
@@ -29,6 +29,16 @@ void GLPrimitivePoint::draw(bool simplest) {
|
||||
|
||||
|
||||
|
||||
void GLPrimitiveLine::draw(bool simplest) {
|
||||
glColor3f(material_.color_diffuse.redF(), material_.color_diffuse.greenF(), material_.color_diffuse.blueF());
|
||||
glBegin(GL_LINES);
|
||||
glVertex3d(p0.x(), p0.y(), p0.z());
|
||||
glVertex3d(p1.x(), p1.y(), p1.z());
|
||||
glEnd();
|
||||
}
|
||||
|
||||
|
||||
|
||||
GLPrimitiveCube::GLPrimitiveCube(double width, double length, double height, QVector3D pos): GLObjectBase() {
|
||||
geom_prim = Quads;
|
||||
w = width;
|
||||
@@ -101,3 +111,75 @@ void GLPrimitiveCube::init() {
|
||||
is_init = true;
|
||||
vbo.rebuffer();
|
||||
}
|
||||
|
||||
|
||||
GLPrimitiveEllipsoid::GLPrimitiveEllipsoid(double width, double length, double height, int seg_wl, int seg_h, QVector3D pos) {
|
||||
geom_prim = GLObjectBase::Triangles;
|
||||
w = width;
|
||||
l = length;
|
||||
h = height;
|
||||
swl = seg_wl;
|
||||
sh = seg_h;
|
||||
moveTo(pos);
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
void GLPrimitiveEllipsoid::putTriangle(const QVector3D & v0, const QVector3D & v1, const QVector3D & v2) {
|
||||
vbo.vertices() << v0.x() << v0.y() << v0.z() << v1.x() << v1.y() << v1.z() << v2.x() << v2.y() << v2.z();
|
||||
QVector3D n = QVector3D::normal(v1 - v0, v2 - v0);
|
||||
for (int i = 0; i < 3; ++i)
|
||||
vbo.normals() << n.x() << n.y() << n.z();
|
||||
return;
|
||||
QVector3D s(w, l, h);
|
||||
n = (v0 * s).normalized(); vbo.normals() << n.x() << n.y() << n.z();
|
||||
n = (v1 * s).normalized(); vbo.normals() << n.x() << n.y() << n.z();
|
||||
n = (v2 * s).normalized(); vbo.normals() << n.x() << n.y() << n.z();
|
||||
}
|
||||
|
||||
|
||||
void GLPrimitiveEllipsoid::init() {
|
||||
QVector<QVector3D> points;
|
||||
vbo.clear();
|
||||
vbo.init();
|
||||
|
||||
int ret = 0, hseg = sh + 1, wlseg = swl + 1;
|
||||
double crw, crl, a, ch, twl;
|
||||
QVector3D cp(0., 0., -h / 2.);
|
||||
points << cp;
|
||||
for (int i = 1; i < hseg; i++) {
|
||||
ch = -cos((double)i / hseg * M_PI);
|
||||
cp.setZ(ch * h / 2.);
|
||||
twl = sqrt(1. - ch * ch) / 2.;
|
||||
crw = twl * w;
|
||||
crl = twl * l;
|
||||
for (int j = 0; j < wlseg * 2; j++) {
|
||||
a = (double)j / wlseg * M_PI;
|
||||
cp.setY(crw * sin(a));
|
||||
cp.setX(crl * cos(a));
|
||||
points << cp;
|
||||
ret = points.size() - 1;
|
||||
if (i == 1)
|
||||
if (j > 0) putTriangle(points[0], points[ret], points[ret - 1]);
|
||||
if (j > 0) {
|
||||
if (i > 1) {
|
||||
putTriangle(points[ret - wlseg * 2 - 1], points[ret], points[ret - 1]);
|
||||
putTriangle(points[ret - wlseg * 2], points[ret], points[ret - wlseg * 2 - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i == 1) putTriangle(points[0], points[ret - wlseg * 2 + 1], points[ret]);
|
||||
else {
|
||||
putTriangle(points[ret - wlseg * 2 + 1], points[ret], points[ret - wlseg * 2]);
|
||||
putTriangle(points[ret - wlseg * 2 + 1], points[ret - wlseg * 2], points[ret - wlseg * 4 + 1]);
|
||||
}
|
||||
}
|
||||
points << QVector3D(0., 0., h / 2.);
|
||||
ret = points.size() - 1;
|
||||
putTriangle(points[ret - 1], points[ret - wlseg * 2], points[ret]);
|
||||
for (int j = 1; j < wlseg * 2; j++)
|
||||
if (j > 0) putTriangle(points[ret - wlseg * 2 + j - 1], points[ret - wlseg * 2 + j], points[ret]);
|
||||
|
||||
is_init = true;
|
||||
vbo.rebuffer();
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "globject.h"
|
||||
|
||||
|
||||
class GLPrimitivePoint: public GLObjectBase
|
||||
{
|
||||
public:
|
||||
@@ -30,6 +31,21 @@ private:
|
||||
double sz;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class GLPrimitiveLine: public GLObjectBase
|
||||
{
|
||||
public:
|
||||
GLPrimitiveLine(QVector3D p0_ = QVector3D(), QVector3D p1_ = QVector3D()) {p0 = p0_; p1 = p1_;}
|
||||
virtual void draw(bool simplest = false);
|
||||
private:
|
||||
QVector3D p0, p1;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class GLPrimitiveCube: public GLObjectBase
|
||||
{
|
||||
public:
|
||||
@@ -39,4 +55,19 @@ private:
|
||||
double w, l, h;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class GLPrimitiveEllipsoid: public GLObjectBase
|
||||
{
|
||||
public:
|
||||
GLPrimitiveEllipsoid(double width = 1., double length = 1., double height = 1., int seg_wl = 10, int seg_h = 10, QVector3D pos = QVector3D());
|
||||
virtual void init();
|
||||
private:
|
||||
void putTriangle(const QVector3D & v0, const QVector3D & v1, const QVector3D & v2);
|
||||
double w, l, h;
|
||||
int swl, sh;
|
||||
};
|
||||
|
||||
|
||||
#endif // GLPRIMITIVE_CUBE_H
|
||||
|
||||
@@ -70,8 +70,12 @@ void createGLTexture(GLuint & tex, int width, int height, const GLenum & format,
|
||||
//glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
if (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_COMPONENT16 || format == GL_DEPTH_COMPONENT24 || format == GL_DEPTH_COMPONENT32)
|
||||
glTexImage2D(target, 0, format, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0);
|
||||
else
|
||||
glTexImage2D(target, 0, format, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
else {
|
||||
int t = GL_UNSIGNED_BYTE;
|
||||
if (format == GL_RGB32F || format == GL_RGB16F)
|
||||
t = GL_FLOAT;
|
||||
glTexImage2D(target, 0, format, width, height, 0, GL_RGBA, t, 0);
|
||||
}
|
||||
//qDebug() << QString::number(glGetError(), 16);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,9 +25,14 @@
|
||||
#if __QNX__ || __QNXNTO__
|
||||
# define QNX
|
||||
#endif
|
||||
#ifdef __APPLE__
|
||||
# define MAC
|
||||
#endif
|
||||
#ifndef WINDOWS
|
||||
# ifndef QNX
|
||||
# define LINUX
|
||||
# ifndef MAC
|
||||
# define LINUX
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
#if __GNUC__
|
||||
@@ -39,10 +44,16 @@
|
||||
#ifdef WINDOWS
|
||||
# include "GLee.h"
|
||||
#else
|
||||
# include <GL/gl.h>
|
||||
# include <GL/glext.h>
|
||||
# ifdef MAC
|
||||
# include <OpenGL/gl.h>
|
||||
# include <OpenGL/glu.h>
|
||||
# include <GLUT/glut.h>
|
||||
# else
|
||||
# include <GL/gl.h>
|
||||
# include <GL/glext.h>
|
||||
# include <GL/glu.h>
|
||||
# endif
|
||||
#endif
|
||||
#include <GL/glu.h>
|
||||
#include <qgl.h>
|
||||
#include <cmath>
|
||||
#include <float.h>
|
||||
@@ -79,6 +90,10 @@
|
||||
#define M_2PI 6.28318530717958647692
|
||||
#define M_PI_3 1.04719755119659774615
|
||||
|
||||
#ifndef GL_RGBA16F
|
||||
# define GL_RGBA16F GL_RGBA16F_ARB
|
||||
#endif
|
||||
|
||||
using std::complex;
|
||||
|
||||
#ifndef PIP_VERSION
|
||||
@@ -270,7 +285,6 @@ public:
|
||||
QVector3D angles() const {return QVector3D(angle_xy, angle_roll, angle_z);}
|
||||
QVector3D direction() const {return (aim_ - pos_).normalized();}
|
||||
QVector3D directionXY() const {QVector3D tv = aim_ - pos_; return QVector3D(tv.x(), tv.y(), 0.).normalized();}
|
||||
QVector3D pointFromViewport(int x, int y, double z = 0.);
|
||||
double FOV() const {return fov_;}
|
||||
double distance() const {return (pos_ - aim_).length();}
|
||||
double angleZ() const {return angle_z;}
|
||||
@@ -285,8 +299,9 @@ public:
|
||||
void anglesFromPoints();
|
||||
void apply(const GLdouble & aspect = 1.);
|
||||
void assign(const Camera & c) {pos_ = c.pos_; aim_ = c.aim_; fov_ = c.fov_; angle_z = c.angle_z; angle_xy = c.angle_xy; angle_roll = c.angle_roll; angle_limit_lower_xy = c.angle_limit_lower_xy; angle_limit_upper_xy = c.angle_limit_upper_xy;}
|
||||
|
||||
QVector3D pointFromViewport(int x_, int y_, double z_);
|
||||
private:
|
||||
|
||||
QVector3D pos_;
|
||||
QVector3D aim_;
|
||||
GLdouble fov_;
|
||||
@@ -297,11 +312,11 @@ private:
|
||||
GLdouble angle_roll;
|
||||
GLdouble angle_limit_lower_xy;
|
||||
GLdouble angle_limit_upper_xy;
|
||||
GLdouble modelview[16], projection[16];
|
||||
GLint viewport[4];
|
||||
bool mirror_x;
|
||||
bool mirror_y;
|
||||
GLint viewport[4];
|
||||
GLdouble projection[16];
|
||||
GLdouble modelview[16];
|
||||
|
||||
};
|
||||
|
||||
extern Camera * currentCamera;
|
||||
@@ -490,7 +505,7 @@ class QGLViewBase
|
||||
public:
|
||||
QGLViewBase() {}
|
||||
Camera & camera() {return camera_;}
|
||||
void setCamera(const Camera &cam) {camera_ = cam;}
|
||||
void setCamera(const Camera & camera) {camera_ = camera;}
|
||||
protected:
|
||||
virtual void collectLights() = 0;
|
||||
Camera camera_;
|
||||
|
||||
@@ -18,15 +18,92 @@
|
||||
|
||||
#include <QApplication>
|
||||
#include <QCleanlooksStyle>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include "mainwindow.h"
|
||||
#include <GL/glew.h>
|
||||
//#include "mainwindow.h"
|
||||
#include "unistd.h"
|
||||
#include <GL/freeglut.h>
|
||||
|
||||
/*void display ()
|
||||
{
|
||||
qDebug() << (const char*)glGetString(GLUT_VERSION);
|
||||
qDebug() << (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION);
|
||||
usleep(200000);
|
||||
}*/
|
||||
template <typename T, int N>
|
||||
struct garray {
|
||||
garray(T * _i) {for (int i = 0; i < N; ++i) _c[i] = &(_i[i]);}
|
||||
T * _c[N];
|
||||
garray<T, N> & operator =(const garray<T, N> & o) {for (int i = 0; i < N; ++i) *_c[i] = *(o._c[i]); return *this;};
|
||||
template <int ON>
|
||||
garray<T, N> & operator =(const garray<T, ON> & o) {for (int i = 0; i < qMin(N, ON); ++i) *_c[i] = *(o._c[i]); return *this;};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class gvec3 {
|
||||
public:
|
||||
gvec3(T def = T()) {x = y = z = def;}
|
||||
union {
|
||||
T xyz[3];
|
||||
struct {T x, y, z;};
|
||||
};
|
||||
private:
|
||||
T _c[3];
|
||||
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
QDebug operator<<(QDebug d, const gvec3<T> & c) {
|
||||
d.nospace() << "(" << c.x << ", " << c.y << ", " << c.z << ")";
|
||||
return d.space();
|
||||
}
|
||||
|
||||
typedef gvec3<float> vec3;
|
||||
typedef gvec3<int> ivec3;
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
/*float f[3] = {0., 1., 2.};
|
||||
float f2[3] = {-1., -1., -1.};
|
||||
garray<float, 3> gar(f2);
|
||||
qDebug() << f2[0] << f2[1] << f2[2];
|
||||
gar = garray<float, 3>((float[3]){f[2], f[1], f[0]});
|
||||
qDebug() << f2[0] << f2[1] << f2[2];*/
|
||||
/*vec3 v0, v1(20);
|
||||
v0.y = 10;
|
||||
qDebug() << v0 << v1;*/
|
||||
|
||||
/*glutInit ( &argc, argv );
|
||||
glutInitDisplayMode ( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
|
||||
glutInitWindowSize ( 500, 500 );
|
||||
|
||||
// prepare context for 3.3
|
||||
glutInitContextVersion ( 3, 3 );
|
||||
glutInitContextFlags ( GLUT_FORWARD_COMPATIBLE | GLUT_DEBUG );
|
||||
glutInitContextProfile ( GLUT_CORE_PROFILE );
|
||||
glutCreateWindow ( "Geometry shader example - particles" );
|
||||
glutDisplayFunc ( display );
|
||||
glewInit ();
|
||||
if ( !GLEW_VERSION_3_3 )
|
||||
{
|
||||
printf ( "OpenGL 3.3 not supported.\n" );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
glutMainLoop();
|
||||
*/
|
||||
return 0;
|
||||
QApplication a(argc, argv);
|
||||
/*QGLFormat f;
|
||||
f.setVersion(3, 3);
|
||||
f.setSampleBuffers(true);
|
||||
f.setProfile(QGLFormat::CoreProfile);
|
||||
QGLFormat::setDefaultFormat(f);*/
|
||||
//QApplication::setStyle(new QCleanlooksStyle());
|
||||
QDir::setCurrent(a.applicationDirPath());
|
||||
//a.setWindowIcon(QIcon(":/icons/peri4_paint.png"));
|
||||
MainWindow w;
|
||||
w.show();
|
||||
//MainWindow w;
|
||||
//w.show();
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
@@ -19,15 +19,19 @@
|
||||
#include "mainwindow.h"
|
||||
#include <QGraphicsRectItem>
|
||||
|
||||
#define EARTH_H 6356863.019 // m
|
||||
#define EARTH_WL 6378245.000 // m
|
||||
|
||||
MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow() {
|
||||
setupUi(this);
|
||||
colorHalo->setColor(view->selectionHaloColor());
|
||||
|
||||
sel_obj = 0;
|
||||
treeProperties->assignObject(view);
|
||||
//spinSliderShine->setDecimals(2);
|
||||
view->setFrameShape(QFrame::NoFrame);
|
||||
view->setRenderer(new RendererDeferredShading(view));
|
||||
//view->setRenderer(new RendererDeferredShading(view));
|
||||
view->setRenderer(new RendererSimple(view));
|
||||
view->setMouseSelectionEnabled(true);
|
||||
view->setMouseRotateEnabled(true);
|
||||
view->setBackColor(Qt::lightGray);
|
||||
@@ -36,10 +40,10 @@ MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow()
|
||||
o->setWindowOpacity(.666);
|
||||
view->addObject(o, Qt::Window);*/
|
||||
view->start(-1);
|
||||
obj = loadFrom3DSFile("data/test.3DS", 0.15);
|
||||
/**obj = loadFrom3DSFile("data/test.3DS", 0.15);
|
||||
m.reflectivity = 1;
|
||||
m.reflection.loadPathesFromDirectory("data/e");
|
||||
obj->child("sphere001")->setMaterial(m);
|
||||
obj->child("sphere001")->setMaterial(m);*/
|
||||
|
||||
|
||||
//m.shine = 40;
|
||||
@@ -55,16 +59,41 @@ MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow()
|
||||
//obj->child("teapot")->setRenderMode(GLObjectBase::Point);
|
||||
//obj->child("teapot")->setLineWidth(2.);
|
||||
//obj->child("cone")->setRenderMode(GLObjectBase::Line);
|
||||
///view->camera().setAim(obj->child("sphere001")->pos());
|
||||
|
||||
obj = new GLPrimitiveEllipsoid(EARTH_WL / 1E+6, EARTH_WL / 1E+6, EARTH_H / 1E+6, 500, 500);//GLPrimitiveCube();
|
||||
view->addObject(obj);
|
||||
view->camera().setAim(obj->child("sphere001")->pos());
|
||||
|
||||
double al = 7.;
|
||||
obj = new GLPrimitiveLine(QVector3D(0, 0, -al), QVector3D(0, 0, al));
|
||||
obj->material().color_diffuse = Qt::darkBlue; obj->setAcceptLight(false);
|
||||
view->addObject(obj);
|
||||
obj = new GLPrimitiveLine(QVector3D(-al, 0, 0), QVector3D(al, 0, 0));
|
||||
obj->material().color_diffuse = Qt::darkRed; obj->setAcceptLight(false);
|
||||
view->addObject(obj);
|
||||
obj = new GLPrimitiveLine(QVector3D(0, -al, 0), QVector3D(0, al, 0));
|
||||
obj->material().color_diffuse = Qt::darkGreen; obj->setAcceptLight(false);
|
||||
view->addObject(obj);
|
||||
|
||||
double lat = deg2rad*(-85.), lng = deg2rad*(15.);
|
||||
obj = new GLPrimitiveLine(QVector3D(), QVector3D(cos(lng)*cos(lat), sin(lng)*cos(lat), sin(lat)/*(EARTH_H/EARTH_WL)*/)*5);
|
||||
view->addObject(obj);
|
||||
|
||||
view->camera().setPos(QVector3D(10, -20, 20));
|
||||
view->camera().setAim(QVector3D());
|
||||
view->camera().flyToDistance(10);
|
||||
view->setMouseSelectionEnabled(false);
|
||||
view->setSelectionHaloEnabled(false);
|
||||
view->setHoverHaloEnabled(false);
|
||||
Light * l = new Light(view->camera().pos());
|
||||
l->intensity = 0.8;
|
||||
view->addObject(l);
|
||||
//view->light(0)->light_type = Light::Omni;
|
||||
//obj = loadFrom3DSFile("34.3DS", 0.03);
|
||||
//view->addObject(obj);
|
||||
//view->camera().moveUp(5, true);
|
||||
|
||||
ps = new GLParticlesSystem(QVector3D(0,0,5));
|
||||
/**ps = new GLParticlesSystem(QVector3D(0,0,5));
|
||||
ps->setEmitterType(GLParticlesSystem::Box);
|
||||
ps->setBirthRate(5);
|
||||
ps->setSize(1.);
|
||||
@@ -74,17 +103,17 @@ MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow()
|
||||
ps->setSpeedDirectionJitter(1);
|
||||
//ps->setTextureScale(2, 2);
|
||||
ps->setAddVerticalFaceEnabled(true);
|
||||
ps->addForce(QVector3D(0,0,-0.98/20));
|
||||
ps->addForce(QVector3D(0,0,-0.98/20));*/
|
||||
//ps->material().diffuse.bitmap_path = "expl_07.png";
|
||||
//view->addObject(ps);
|
||||
|
||||
box = new GLPrimitiveCube();
|
||||
/**box = new GLPrimitiveCube();
|
||||
box->setSelectable(false);
|
||||
box->setRenderMode(GLObjectBase::Line);
|
||||
box->setLineWidth(2.);
|
||||
view->addObject(box);
|
||||
box->hide();
|
||||
while (view->lightsCount() >= 3) view->removeLight(view->lightsCount() - 1);
|
||||
box->hide();*/
|
||||
while (view->lightsCount() >= 5) view->removeLight(view->lightsCount() - 1);
|
||||
//view->addObject(box);
|
||||
|
||||
//obj = obj->clone(true);
|
||||
@@ -103,7 +132,7 @@ MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow()
|
||||
}*/
|
||||
startTimer(1000/60);
|
||||
|
||||
connect(view, SIGNAL(hoverChanged(GLObjectBase*,GLObjectBase*)), this, SLOT(hoverChanged(GLObjectBase*,GLObjectBase*)));
|
||||
//connect(view, SIGNAL(hoverChanged(GLObjectBase*,GLObjectBase*)), this, SLOT(hoverChanged(GLObjectBase*,GLObjectBase*)));
|
||||
connect(view, SIGNAL(selectionChanged(GLObjectBase*,GLObjectBase*)), this, SLOT(selectionChanged(GLObjectBase*,GLObjectBase*)));
|
||||
connect(view, SIGNAL(glInitializeDone()), this, SLOT(glInit()));
|
||||
connect(matEditor, SIGNAL(changed()), this, SLOT(materialChanged()));
|
||||
@@ -114,7 +143,7 @@ MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow()
|
||||
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
delete ps;
|
||||
//delete ps;
|
||||
}
|
||||
|
||||
|
||||
@@ -129,6 +158,8 @@ void MainWindow::changeEvent(QEvent * e) {
|
||||
|
||||
void MainWindow::timerEvent(QTimerEvent * ) {
|
||||
static double t = 0.;
|
||||
view->light(0)->setPos(view->camera().pos());
|
||||
((RendererSimple*)(view->renderer()))->mpos = view->mapFromGlobal(QCursor::pos());
|
||||
/*obj->child("tor")->rotateX(0.5);
|
||||
obj->child("tor")->rotateZ(0.1);
|
||||
obj->child("cone")->rotateZ(1);
|
||||
@@ -169,7 +200,7 @@ void MainWindow::selectionChanged(GLObjectBase * cur, GLObjectBase * prev) {
|
||||
sel_obj = cur;
|
||||
//qDebug() << "selected" << (cur != 0 ? cur->name() : "0");
|
||||
labelName->setText(cur != 0 ? cur->name() : "");
|
||||
if (cur == 0) box->hide();
|
||||
/**if (cur == 0) box->hide();
|
||||
else {
|
||||
box->setScale(cur->boundingBox().size());
|
||||
box->setPos(cur->boundingBox().pos());
|
||||
@@ -178,7 +209,7 @@ void MainWindow::selectionChanged(GLObjectBase * cur, GLObjectBase * prev) {
|
||||
ps->setEmitterRect(b);
|
||||
cur->addChild(box);
|
||||
box->show();
|
||||
}
|
||||
}*/
|
||||
objectEditor->setObject(sel_obj);
|
||||
if (sel_obj == 0) return;
|
||||
matEditor->setMaterial(sel_obj->material());
|
||||
|
||||
@@ -19,8 +19,25 @@
|
||||
#include "renderer_simple.h"
|
||||
|
||||
|
||||
RendererSimple::RendererSimple(QGLView * view_): GLRendererBase(view_), fbo(2) {
|
||||
RendererSimple::RendererSimple(QGLView * view_): GLRendererBase(view_), fbo(2)
|
||||
, fbo_c(1, true, GL_RGBA32F) /// WARNING
|
||||
{
|
||||
shader_fxaa = 0;
|
||||
shader = 0; /// WARNING
|
||||
}
|
||||
|
||||
|
||||
void RendererSimple::reloadShaders() {
|
||||
if (shader_fxaa == 0) shader_fxaa = new QGLShaderProgram(view.context());
|
||||
loadShaders(shader_fxaa, "FXAA", "shaders");
|
||||
if (shader == 0) shader = new QGLShaderProgram(view.context()); /// WARNING
|
||||
loadShaders(shader, "test", "shaders"); /// WARNING
|
||||
}
|
||||
|
||||
|
||||
void RendererSimple::resizeFBO(int w, int h) {
|
||||
fbo.resize(w, h);
|
||||
fbo_c.resize(w, h); /// WARNING
|
||||
}
|
||||
|
||||
|
||||
@@ -52,9 +69,25 @@ void RendererSimple::renderScene() {
|
||||
}
|
||||
view.camera().apply(view.aspect);
|
||||
setupLights(l, 8);
|
||||
//glEnable(GL_MULTISAMPLE);
|
||||
|
||||
|
||||
fbo_c.bind();
|
||||
glClearFramebuffer();
|
||||
shader->bind(); /// WARNING
|
||||
renderObjects(GLObjectBase::Solid, l, 0, true, true, view.isFogEnabled());
|
||||
renderObjects(GLObjectBase::Transparent, l, 0, true, true, view.isFogEnabled());
|
||||
shader->release(); /// WARNING
|
||||
if (QRect(QPoint(), fbo_c.size()).contains(mpos)) {
|
||||
//qDebug() << mpos;
|
||||
GLfloat data[4] = {0, 0, 0, 0};
|
||||
glReadPixels(mpos.x(), fbo_c.height() - mpos.y(), 1, 1, GL_RGBA, GL_FLOAT, data);
|
||||
qDebug() << QVector3D(data[0], data[1], data[2]);
|
||||
}
|
||||
fbo_c.release();
|
||||
renderObjects(GLObjectBase::Solid, l, 0, true, true, view.isFogEnabled());
|
||||
|
||||
|
||||
//renderObjects(GLObjectBase::Solid, l, 0, true, true, view.isFogEnabled());
|
||||
//renderObjects(GLObjectBase::Transparent, l, 0, true, true, view.isFogEnabled());
|
||||
if (passes > 1) {
|
||||
glSetLightEnabled(false);
|
||||
glSetCapEnabled(GL_BLEND);
|
||||
|
||||
@@ -28,15 +28,19 @@ public:
|
||||
virtual ~RendererSimple() {if (shader_fxaa != 0) delete shader_fxaa;}
|
||||
|
||||
virtual void renderScene();
|
||||
|
||||
QPoint mpos;
|
||||
|
||||
protected:
|
||||
virtual void init(int width, int height) {fbo.resize(width, height);}
|
||||
virtual void resize(int width, int height) {fbo.resize(width, height);}
|
||||
virtual void reloadShaders() {if (shader_fxaa == 0) shader_fxaa = new QGLShaderProgram(view.context()); loadShaders(shader_fxaa, "FXAA", "shaders");}
|
||||
virtual void init(int width, int height) {resizeFBO(width, height);}
|
||||
virtual void resize(int width, int height) {resizeFBO(width, height);}
|
||||
virtual void reloadShaders();
|
||||
|
||||
private:
|
||||
GLFramebuffer fbo;
|
||||
QGLShaderProgram * shader_fxaa;
|
||||
void resizeFBO(int w, int h);
|
||||
|
||||
GLFramebuffer fbo , fbo_c;
|
||||
QGLShaderProgram * shader_fxaa , * shader;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user