PDA

View Full Version : Unable to set the view port for graphicsview



A9am
20th December 2012, 04:37
Hi,

If I am using setviewport for the graphicsview , I am getting a transparent screen .

view->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));

Can anyone please suggest any solution?


Thanks

Jonny174
20th December 2012, 05:05
MainWindow::MainWindow( QWidget *parent ):
QMainWindow( parent )
{
GraphicsView *view = new GraphicsView;
view->setViewport( new QGLWidget( QGLFormat( QGL::SampleBuffers | QGL::AlphaChannel | QGL::Rgba ) ) );
view->setViewportUpdateMode( QGraphicsView::FullViewportUpdate );
view->setScene( new OpenGLScene );

resize( 320, 240 );
setCentralWidget( view );
}

GraphicsView::GraphicsView()
{
}

void GraphicsView::resizeEvent( QResizeEvent *e )
{
if (scene())
scene()->setSceneRect( QRect( QPoint( 0, 0 ), e->size() ) );

QGraphicsView::resizeEvent(e);
}

OpenGLScene::OpenGLScene()
{
}

OpenGLScene::~OpenGLScene()
{
}

void OpenGLScene::drawBackground( QPainter */*painter*/, const QRectF &/*rect*/ )
{
glClearColor( 1.0f, 1.0f, 1.0f, 1.0f );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glMatrixMode( GL_PROJECTION );

glPushMatrix();
glLoadIdentity();
glViewport( 0, 0, int( width() ), int( height() ) );
//glOrtho( -width() / 2.0, width() / 2.0, -height() / 2.0, height() / 2.0, -1.0, 1000.0 );
glOrtho( 0.0, width(), height(), 0.0, -1.0, 1000.0 );

glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glLoadIdentity();
// DRAW HERE
glPopMatrix();
glPopMatrix();

//QTimer::singleShot( 1, this, SLOT(update()) );
}

A9am
20th December 2012, 06:16
Thanks Jonny . I compiled and ran the code. But I am getting a transparent screen again..:(

With the following debug outputs..
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 19 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 19 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 14 (Unknown request)
Resource id: 0x64
QGLTempContext: No GL capable X visuals available.
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 19 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 19 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 14 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 19 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 19 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 14 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 19 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 19 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 14 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 19 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 19 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 14 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 19 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 19 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 14 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 19 (Unknown request)
Resource id: 0x5600007
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 19 (Unknown request)
Resource id: 0x5600007
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 14 (Unknown request)
Resource id: 0x5600007
QGLTempContext: No GL capable X visuals available.
QGLContext::makeCurrent(): Cannot make invalid context current.
In drwa
QGLContext::makeCurrent(): Cannot make invalid context current.
In drwa
QGLContext::makeCurrent(): Cannot make invalid context current.
In drwa
QGLContext::makeCurrent(): Cannot make invalid context current.
In drwa
QGLContext::makeCurrent(): Cannot make invalid context current.
In drwa
QGLContext::makeCurrent(): Cannot make invalid context current.
In drwa
QGLContext::makeCurrent(): Cannot make invalid context current.
In drwa

Added after 24 minutes:

My GLWidget is not valid bool result = widget->isValid(); returns false.

What can I do to make it valid ?

Jonny174
20th December 2012, 07:09
Put here your project

Try this in MainWindow:


view = new GraphicsView;

wgt = new QGLWidget( QGLFormat( QGL::SampleBuffers | QGL::AlphaChannel | QGL::Rgba ) );

QGLFormat frm = wgt->format();
frm.setSamples(4);

wgt->makeCurrent();

scene = new OpenGLScene( wgt );

view->setViewport( wgt );
view->setViewportUpdateMode( QGraphicsView::FullViewportUpdate );
view->setScene( scene );

A9am
20th December 2012, 07:24
I tried the above code , I am getting a window plus the following output on execution .

X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 19 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 19 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 14 (Unknown request)
Resource id: 0x64
QGLTempContext: No GL capable X visuals available.
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 19 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 19 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 14 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 19 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 19 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 14 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 19 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 19 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 14 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 19 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 19 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 14 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 19 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 19 (Unknown request)
Resource id: 0x64
X Error: BadRequest (invalid request code or no such operation) 1
Extension: 136 (Uknown extension)
Minor opcode: 14 (Unknown request)
Resource id: 0x64
QGLContext::makeCurrent(): Cannot make invalid context current.
XIO: fatal IO error 11 (Resource temporarily unavailable) on X server "(m"
after 495 requests (494 known processed) with 0 events remaining.



The code below is used:


QGLFormat *format =new QGLFormat(QGL::SampleBuffers | QGL::AlphaChannel | QGL::Rgba );
bool res=format->hasOpenGL(); //returns true


QGLContext *context = new QGLContext(*format);
res = context->isValid(); //returns false


bool result = widget->isValid(); //returns false

Jonny174
20th December 2012, 07:25
Put minimal project here

A9am
20th December 2012, 07:28
Hi Jonny .. Even for OpenGl example"Hellogl" code from Qt I am getting a transparent screen.. So Please forget about my project. Atleast I should be able to get the sample output properly.

Jonny174
20th December 2012, 07:35
Maybe reinstall Qt helps you

A9am
20th December 2012, 07:38
I have three different versions installed in my system Qt-4.5.2 , Qt-4.8.2 and Qt-4.7.2 . In all samples I am getting same output. Should I need to install any other libraries for OpenGL ??

Jonny174
20th December 2012, 10:34
I have three different versions installed in my system Qt-4.5.2 , Qt-4.8.2 and Qt-4.7.2 . In all samples I am getting same output. Should I need to install any other libraries for OpenGL ??
No.

Try install new video drivers.

Try put XInitThreads() function in constructor.

http://stackoverflow.com/questions/5686684/x11-error-badrequest-when-running-opengl-applications

Try to do something without using Qt Widgets. Purely in C++ and OpenGL.

wysota
20th December 2012, 21:04
I think this error message says it all:


QGLTempContext: No GL capable X visuals available.

You cannot use a GL format your graphics driver and X11 configuration don't support.

A9am
28th December 2012, 13:30
Hi,
Now I installed a graphics card and driver on my system. OpenGL Examples are working with this. I have an application in which I am using the following part of code

scene = new QGraphicsScene(this);

scene->setSceneRect(QRectF(centerX-2000000, centerY-2000000, 4000000,4000000));

view = new QGraphicsView(this);
view->setScene(scene);
view->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
view->setGeometry(0,0,viewRangeX,viewRangeY);
view->setDragMode(QGraphicsView::ScrollHandDrag);
view->centerOn(centerX,centerY);
view->setBackgroundBrush(Qt::black);
view->scale(viewRangeX/1000000,viewRangeX/1000000);

view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff) ;
view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOf f);




And I am adding a radar video item into this scene. The radar should scan the whole area (360 degrees).
But when I am using the setviewport function (text in red) , the scan stops. Without this line its scanning properly. But I want to use the QGLWidget as viewport. Kindly give some suggestions.


Thanks

wysota
28th December 2012, 14:01
What if you call:


view->setViewport(new QGLWidget);

A9am
31st December 2012, 06:35
Same result with
view->setViewport(new QGLWidget);

:(

A9am
7th January 2013, 04:06
In one of the systems , the application was working fine with proper scan. But once I installed nvidia driver , the application is not working with setviewport.
view->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));



And when I uninstalled the nvidia driver , application is running without any problem .
Can anyone please tell me why this is happening??
:confused:

wysota
7th January 2013, 11:21
Misconfigured driver? Which driver are you using, the proprietiary one?

A9am
8th January 2013, 05:17
Yes. The driver downloaded from the nvidia site