I am trying to display a 64x64 in opengl. The texture loads but I cant get it to display in a square and on the top left corner of the screen. Heres my code for the GLWidget in qt
#include "glwidget.h"
GLWidget::GLWidget(QWidget *parent) :
QGLWidget(parent)
{
}
void GLWidget::initializeGL(){
glClearColor(1, 1, 1 , 0);
gluPerspective(45, 640/480, 1, 500);
glEnable(GL_MULTISAMPLE);
glEnable(GL_AMD_performance_monitor);
glEnable(GL_TEXTURE_2D);
GLWidget::loadTexture2(":/images/Block.bmp", GLWidget::backgroundimage);
}
void GLWidget::paintGL(){
glClearColor(0.4f, 0.1f, 0.1f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D, backgroundimage);
glBegin(GL_QUADS);
glTexCoord2f(0,1); glVertex2f(0, 0);
glTexCoord2f(0,0); glVertex2f(0, 64);
glTexCoord2f(1,0); glVertex2f(64, 0);
glTexCoord2f(1,1); glVertex2f(64, 64);
glEnd();
glFlush();
}
void GLWidget::resizeGL(int w, int h){
}
QImage GLWidget::loadTexture2(char *filename, GLuint &textureID){
glEnable(GL_TEXTURE_2D); // Enable texturing
glGenTextures(1, &textureID); // Obtain an id for the texture
glBindTexture(GL_TEXTURE_2D, textureID); // Set as the current texture
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
QImage im(filename);
QImage tex = QGLWidget::convertToGLFormat(im);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width(), tex.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, tex.bits());
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glDisable(GL_TEXTURE_2D);
return tex;
}