50#include <ACG/GL/acg_glew.hh>
51#include "QtWidgetNode.hh"
52#include <ACG/Geometry/Types/PlaneT.hh>
53#include <ACG/Utils/ImageConversion.hh>
55#include <QApplication>
67bool QtWidgetNode::NodeEventFilter::eventFilter(QObject *_obj, QEvent *_event)
71 if (_event->type() == QEvent::LayoutRequest || _event->type() == QEvent::Paint)
75 repaint = repaint && node_->planeCreated_;
77 bool result = QObject::eventFilter(_obj, _event);
102 planeCreated_(false),
104 anisotropicSupport_(false)
123 glDeleteTextures(1,&texID_);
133 widget_->removeEventFilter(ef_);
139 planeCreated_ =
false;
145 widget_->installEventFilter(ef_);
171 _bbMin.
minimize( pos0 + xDird + yDird);
175 _bbMax.
maximize( pos1 + xDird + yDird);
199 const size_t buffersize = 4*8;
200 float vboData_[buffersize] = { 0.0,0.0,0.0,
206 (
float)outerCorner[0],(float)outerCorner[1],(
float)outerCorner[2],
215 glGenBuffers(1, &
vbo_);
218 glBindBuffer(GL_ARRAY_BUFFER_ARB,
vbo_);
221 glBufferData(GL_ARRAY_BUFFER_ARB, buffersize *
sizeof(
float), &vboData_[0], GL_STATIC_DRAW_ARB);
223 glBindBuffer(GL_ARRAY_BUFFER_ARB, 0);
230 widget_->removeEventFilter(ef_);
232 widget_->installEventFilter(ef_);
234 QImage image = pix.toImage();
235 image = ACG::Util::convertToGLFormat(image);
240 glGenTextures( 1, &texID_ );
243 glBindTexture( GL_TEXTURE_2D, texID_ );
245 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
246 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
247 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
248 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
250 if (anisotropicSupport_)
252 GLfloat anisotropyValue;
253 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropyValue);
254 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropyValue);
257 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width(), image.height(), 0, GL_RGBA,
258 GL_UNSIGNED_BYTE, image.bits());
259 glGenerateMipmap(GL_TEXTURE_2D);
267 oldWidgetHeight_=
widget_->height();;
273 projNullPos = _state.
unproject(projNullPos);
277 const ACG::Vec3d xDirection =
Vec3d(projPos[0]-projNullPos[0],0.0,0.0);
278 const ACG::Vec3d yDirection =
Vec3d(0.0,projPos[1]-projNullPos[1],0.0);
290 double heightRatio =
widget_->height() / (double)oldWidgetHeight_;
293 oldWidgetHeight_ =
widget_->height();
319 ACG::Vec3d rayDir = (unprojEventPos - _state.
eye()).normalize();
320 if (!intersectPlane.intersect_ray(_state.
eye(),_state.
eye()+rayDir,intersecPos,distance))
325 ACG::Vec3d toInter = intersecPos - topLeftCorner;
328 double sX = (xDir | toInter)/xDir.
sqrnorm();
329 double sY = (yDir | toInter)/yDir.
sqrnorm();
331 if (sX < 0.0 || sX > 1.0 || sY < 0.0 || sY > 1.0)
335 QPoint widgetEventPos(sX *
widget_->width(), sY *
widget_->height());
338 QWidget *childWidget =
widget_->childAt(widgetEventPos);
343 widgetEventPos -= childWidget->pos();
346 QMouseEvent event(_event->type(),widgetEventPos,_event->button(),_event->buttons(),_event->modifiers());
347 QApplication::sendEvent(childWidget,&event);
350 QEvent paintEvent(QEvent::Paint);
351 QApplication::sendEvent(
widget_,&paintEvent);
373 ro.debugName = (std::string(
"QtWidgetNode: ")+
name()).c_str();
381 planeCreated_ =
true;
387 _state.
translate(pos[0], pos[1], pos[2]);
401 texture.type = GL_TEXTURE_2D;
402 texture.shadow =
false;
415 ro.setMaterial(&localMaterial);
418 ro.glDrawArrays(GL_QUADS, 0, 4);
void pop_modelview_matrix()
pop modelview matrix
Vec3d eye() const
get eye point
const GLMatrixd & modelview() const
get modelview matrix
void translate(double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
translate by (_x, _y, _z)
Vec3d unproject(const Vec3d &_winPoint) const
unproject point in window coordinates _winPoint to world coordinates
int viewport_height() const
get viewport height
static void deleteBuffers(GLsizei n, const GLuint *buffers)
void push_modelview_matrix()
push modelview matrix
void setPlane(const ACG::Vec3d &_position, const ACG::Vec3d &_xDirection, const ACG::Vec3d &)
Set plane.
virtual void addRenderObject(RenderObject *_renderObject)
Callback for the scenegraph nodes, which send new render objects via this function.
bool hidden()
Is node not visible (status != Active)?
void setDirty(bool _dirty=true)
mark node for redrawn
std::string name() const
Returns: name of node (needs not be unique)
void baseColor(const Vec4f &_c)
set the base color (Sets the baseColor which is the same as the emission(const Vec4f& _c) )
void specularColor(const Vec4f &_s)
set the specular color
void ambientColor(const Vec4f &_a)
set the ambient color.
void diffuseColor(const Vec4f &_d)
set the diffuse color.
void addElement(const VertexElement *_pElement)
decltype(std::declval< S >() *std::declval< S >()) sqrnorm() const
compute squared euclidean norm
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
DrawMode POINTS
draw unlighted points using the default base color
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
Namespace providing different geometric functions concerning angles.
bool checkExtensionSupported(const std::string &_extension)
@ VERTEX_USAGE_NORMAL
"inNormal"
@ VERTEX_USAGE_POSITION
"inPosition"
@ VERTEX_USAGE_TEXCOORD
"inTexCoord"
VectorT< double, 3 > Vec3d
Interface class between scenegraph and renderer.
ShaderGenDesc shaderDesc
Drawmode and other shader params.
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
void addTexture(const Texture &_t)
adds a texture to stage RenderObjects::numTextures()
GLMatrixd modelview
Modelview transform.
GLuint vertexBuffer
VBO, IBO ids, ignored if VAO is provided.
void initFromState(GLState *_glState)
Initializes a RenderObject instance.