3 Dimensions using opengl
Hi all,
I have implemented basic shapes using QFrame ,using normal painting. I want to
achieve the same using opengl & I will have an option in the menu for opengl. If the
user selects that option I want to redraw all the items on QFrame using opengl. How to achieve it using qt4??? or first off is that possible.
Thanks
Re: 3 Dimensions using opengl
How about using QAbstractScrollArea and using the function QAbstractScrollArea::setViewport ?? to set the viewport to QGLWidget....
see the chips demo...
will it solve ur purpose ??
Re: 3 Dimensions using opengl
Quote:
Originally Posted by
aamer4yu
How about using QAbstractScrollArea and using the function
QAbstractScrollArea::setViewport ?? to set the viewport to QGLWidget....
see the chips demo...
will it solve ur purpose ??
I wrote a program which reads some data(line circle, polygon etc) through buttons.
For this I subclassed QAbstractScrollArea, reimplemented paintEvent() on viewport() to draw the items. But when I click circle button the display on viewport is very slow. There is so much of lag between drawings.
Can anyone please tell me why?????
Thanks
Re: 3 Dimensions using opengl
cant say much... i was thinking of QGraphicsView.... as it is derived from QAbstractScrollArea
but forgot u are trying for 3 Dimensions :(
Re: 3 Dimensions using opengl
Hi guys,
Please help!!!
I'm really having problem with this and I cannot move ahead. Please throw some light.
Thanks
Re: 3 Dimensions using opengl
Re: 3 Dimensions using opengl
Quote:
Originally Posted by
jacek
I know that site and I'm using it to learn opengl. It is a fantastic tutorial for newbie. Here is the toturial link http://digitalfanatics.org/projects/...chapter14.html
But I want to know, when I use a QAbstractScrollArea why there is so much lag between displaying of items. I think the paintEvent is not called and requires some other event to occur to call it.
I tried using QFrame but unable to proceed further. I now thought to use QGraphicsView to see how it goes.
If you can tell me why there is a lag between displaying of items when I use QFrame, I'll be thankful to you.
Thanks
Re: 3 Dimensions using opengl
Quote:
Originally Posted by
vermarajeev
I tried using QFrame but unable to proceed further. I now thought to use QGraphicsView to see how it goes.
I'm not sure if I undertand your problem properly. Do you want to display those objects on QFrame and QGLWidget at the same time, or do you want to replace QFrame with QGLWidget?
1 Attachment(s)
Re: 3 Dimensions using opengl
Quote:
Originally Posted by
jacek
I'm not sure if I undertand your problem properly. Do you want to display those objects on QFrame and QGLWidget at the same time, or do you want to replace QFrame with QGLWidget?
I draw some objects on QFrame, now on click of a button say '3D Viewer', I want to display those objects on QGLWidget with 3D representation. This means that I already have 2D represntation of objects now I want to get 3D representation.
I just tried using QGraphicsView instead of QFrame by seeing the chips demo. When you see the chips demo, the objects are in 2D representation. Then you click some button 'openGl' the result is again 2D representation. Instead of 2D I want 3D such that I can see the object in all directions by rotating it.
Please see the attached file for more details.
Thanks and eagerly waiting for a reply
Re: 3 Dimensions using opengl
do u mean rotating 2D objects in 3D space ??
if yes, u need to check this
also saw the image u gave... well as far as i got it, u work in 2D and want to show them in 3D.... well if u have fixes number of items, and know what items will be drawn, u can create a different view and add 3D objects to it. i guess a 2D item doesnt have any info how to draw itself in 3D,,,, while a 3D object can be scaled down to 2D projection.
hope i am in right direction in understanding ur problem....
and yeah, is ur 3D view editable ??? i mean do u want items to be manipulated in 3D view, or just show a 3D view of the items ??
Re: 3 Dimensions using opengl
Hi aamer4yu,
Thanks for your reply
Quote:
also saw the image u gave... well as far as i got it, u work in 2D and want to show them in 3D....
Yes you are in right path. I already have some 2D objects and want to show them in 3D.
Quote:
well if u have fixes number of items, and know what items will be drawn, u can create a different view and add 3D objects to it
Is different view a QGlwidget???. If yes I tried it. But get only 2D view.
Now here is the main issue. How do I create a different view and add 3D objects to it. My sense says something like this
//GraphicsView
Code:
paint( &painter );
}
void graphicsView
::paint( QPainter* painter
){ //Draw the object you want
}
void graphicsView::on3DViewerButtonClick(){
m_glWid = new myGLWidget( this ); //here this is QGraphicsView
m_glWid->show();
}
Now I got graphicsView object in QGLWidget. How do I proceed further. I know I need to override
Code:
paintGL()
resizeGL()
initializeGL()
I can even use paintEvent in GLWidget and the call paint member of GraphicsView like this
Code:
painter.begin(this);
m_graphicsView->paint(&painter);
painter.end();
}
But now I get 2D on QGLWidget.
Did you mean something like this. Or Is there something else.
Quote:
and yeah, is ur 3D view editable ??? i mean do u want items to be manipulated in 3D view, or just show a 3D view of the items ??
[/QUOTE]
Yes in some scenario. First I would be interested in representing a 2D object to 3D. If I succeed then move ahead for editing.
Hope I made some sense now. PLease let me know if still there is any confusion.
I'll go through the link you have given and see if I can get it.
Thanks
//I want through the link and could not find QTransform in qt4.2.2.
Re: 3 Dimensions using opengl
i cudnt check the link example.... i dont have admin rights to install it in office.. will chk later when i get home..
also QTransform is a feature of 4.3 I guess ??
and i think u will have to implement a method for drawing ur 2D objects in 3D...but as ur future requirements, i wud say draw and edit in 3D ... u can get a 2D projection frm 3D...
for eg, u draw the objects in 3D.... zoom out a little, and the drawing will appear 2D from far...
rest i will say after seeing that example
Re: 3 Dimensions using opengl
Quote:
Originally Posted by
vermarajeev
I draw some objects on QFrame, now on click of a button say '3D Viewer', I want to display those objects on QGLWidget with 3D representation.
Can't you simply draw them on QGLWidget once in 2D and once in 3D?
Re: 3 Dimensions using opengl
Quote:
Originally Posted by
jacek
Can't you simply draw them on QGLWidget once in 2D and once in 3D?
No! Basically the user has an option to draw in 2D and view the result in 3D. If I need to use QGLWidget for both 2D and 3D then I'll have so much of rework to do. Is it not possible to use what is already existing?
Something like Just send the graphicsView object to QGLwidget and let it draw using opengl APIs.
Waiting eagerly.
Thanks
Re: 3 Dimensions using opengl
Quote:
Originally Posted by
vermarajeev
Something like Just send the graphicsView object to QGLwidget and let it draw using opengl APIs.
This is not a bad idea if you know how to handle the OpenGL-based 3D drawing but consider using the QGraphicsScene object instead. ;)
Re: 3 Dimensions using opengl
Quote:
Originally Posted by
fullmetalcoder
This is not a bad idea if you know how to handle the OpenGL-based 3D drawing but consider using the
QGraphicsScene object instead. ;)
Jacek--> Can you please tell me how do I use QTranform as specified in the link above in qt4.2.2. I think QTranform should make work easier.
fullmetalcoder--> I have written a sample program can you please help me to represent a 2D object to 3D.
//GraphicsView
Code:
s->setSceneRect(-200, -200, 400, 400);
btnOPenGl->setGeometry( 300, 300, 50, 30 );
connect( btnOPenGl, SIGNAL( clicked() ), this, SLOT( onbtnOPenGlClick() ) );
}
graphicsView::~graphicsView()
{}
void graphicsView::onbtnOPenGlClick(){
GLWidget* GLwid = new GLWidget(this);
GLwid->show();
}
void graphicsView
::drawBackground(QPainter *painter,
const QRectF &rect
){ Q_UNUSED(rect);
paint(painter);
}
void graphicsView
::paint(QPainter* painter
){ static const QPoint points
[6] = { };
painter->drawPolygon(points, 6);
}
//QGLWidget
Code:
#include <QGLWidget>
#include "graphicsview.h"
class graphicsView;
{
public:
GLWidget
(graphicsView
* gv,
QWidget *parent
=0 ) {}
protected:
paint.begin(this);
m_graphicsView->paint(&paint);
paint.end();
}
/*void initializeGL()
{
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}
void resizeGL( int width, int height )
{
height = height?height:1;
glViewport( 0, 0, (GLint)width, (GLint)height );
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-1.5f,0.0f,-6.0f);
glBegin(GL_TRIANGLES);
glVertex3f( 0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glEnd();
}*/
private:
graphicsView* m_graphicsView;
};
Thanks
Re: 3 Dimensions using opengl
What kind of 2D objects do you want to represent with 3D version?
Re: 3 Dimensions using opengl
Quote:
Originally Posted by
vermarajeev
Can you please tell me how do I use QTranform as specified in the link above in qt4.2.2. I think QTranform should make work easier.
If I understand your problem correctly, QTransform won't help you --- after you apply QTransform your object still will be flat.
Re: 3 Dimensions using opengl
Lines in 2D can be represented in 3D with simple lines or cylinder.
For simple lines you can use glBegin(GL_LINES), glBegin(GL_LINESTRIP) or glBegin(GL_LINE_LOOP).
Code:
glBegin(GL_LINE_STRIP);
glVertex2f(from_x, from_y);
glVertex2f(to1_x, to1_y);
glVertex2f(to2_x, to2_y);
....
glEnd();
This will draw simple connected line, which can be easily rotated.
Re: 3 Dimensions using opengl
Quote:
Originally Posted by
minimoog
Lines in 2D can be represented in 3D with simple lines or cylinder.
For simple lines you can use glBegin(GL_LINES), glBegin(GL_LINESTRIP) or glBegin(GL_LINE_LOOP).
Code:
glBegin(GL_LINE_STRIP);
glVertex2f(from_x, from_y);
glVertex2f(to1_x, to1_y);
glVertex2f(to2_x, to2_y);
....
glEnd();
This will draw simple connected line, which can be easily rotated.
So you mean to say, I need to redraw the objects again in 3D.
Actually I dont want to redraw the things again.
Anyway since I'm not able to get the what I want I should atleast see how your logic works. Can you please help me to achieve what you have suggested in the above sample program that I have posted.
Thanks