Note that there are some explanatory texts on larger screens.

plurals
  1. POC++/Qt, OpenGL texture mapping
    text
    copied!<p>I'm attempting to render a texture that has been mapped to the graphics video memory. I have used qDebug to test that input of my image, indeed it possesses a 512x512 image which is a power of 2. Yet still when I attempt to render, instead of a texture the result is merely a quad which is white.</p> <p>To note: GLuint m_textureIdents[1]; is correctly defined in GLWidget.h</p> <pre><code>#include "GLWidget.h" GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent) { setMouseTracking(true); m_sceneIndex = SinQuest::SplashScreen; } void GLWidget::setApplicationPath(QString strAppPath) { m_strAppPath = strAppPath; } #include &lt;QDebug&gt; void GLWidget::loadResources(void) { m_imageHandler.addImage(QString(m_strAppPath).append(QDir().toNativeSeparators("\\resources\\images\\")).append("splash_logo.png"), "splash-logo"); QImage glImageData = QGLWidget::convertToGLFormat(*m_imageHandler.getImage("splash-logo")); qDebug() &lt;&lt; glImageData.width() &lt;&lt; ":" &lt;&lt; glImageData.height(); m_textureIdents[0] = 0; glGenTextures(1, &amp;m_textureIdents[0]); glBindTexture(GL_TEXTURE_2D, m_textureIdents[0]); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, glImageData.width(), glImageData.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, glImageData.bits()); } void GLWidget::initializeGL() { glEnable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); glDisable(GL_COLOR_MATERIAL); glEnable(GL_BLEND); glEnable(GL_POLYGON_SMOOTH); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glClearColor(0, 0, 0, 0); } void GLWidget::resizeGL(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, w, 0, h, -1.0l, 1.0l); // set up origin glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void GLWidget::paintGL() { glClearColor( 0.0f, 0.0f, 0.0f, 0.0f); glClear( GL_COLOR_BUFFER_BIT ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glColor3f(1.0f, 1.0f, 1.0f); glShadeModel( GL_FLAT ); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_textureIdents[0]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex2i(0, 0); glTexCoord2f(1.0f, 0.0f); glVertex2i(512, 0); glTexCoord2f(1.0f, 1.0f); glVertex2i(512, 512); glTexCoord2f(0.0f, 1.0f); glVertex2i(0, 512); glEnd(); } void GLWidget::mousePressEvent(QMouseEvent *event) { } void GLWidget::mouseMoveEvent(QMouseEvent *event) { printf("%d, %d\n", event-&gt;x(), event-&gt;y()); } void GLWidget::keyPressEvent(QKeyEvent* event) { switch(event-&gt;key()) { case Qt::Key_Escape: close(); break; default: event-&gt;ignore(); break; } } </code></pre> <p>...</p> <pre><code>int main(int argc, char *argv[]) { QApplication app(argc, argv); QDesktopWidget *pDeskWidget = app.desktop(); // available geometry to obtain resolution for primary screen QRect avGeometry = pDeskWidget-&gt;availableGeometry(pDeskWidget-&gt;primaryScreen()); // create window, set resolution and invoke fullscreen window state GLWidget window; window.setApplicationPath(QCoreApplication::applicationDirPath()); window.loadResources(); window.resize(avGeometry.width(), avGeometry.height()); window.setWindowState(Qt::WindowFullScreen); window.show(); return app.exec(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload