#include "glwidget.h"
GLWidget
::GLWidget(QWidget *parent
) :{
}
void GLWidget::initializeGL()
{
glEnable(GL_TEXTURE_2D);
glClearColor(1,1,0.5,1);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
}
//Setup viewport, projection etc...
void GLWidget::resizeGL(int w, int h)
{
if (h == 0)
{
h = 1;
}
}
//Draw the Scene
void GLWidget::paintGL() //corresponds to DrawGLScene
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
//glTranslatef(x, y, z)
//glTranslatef(0.0f,0.0f,-10.0f);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glBegin(GL_QUADS);
//Bottom Left
glColor3f(0.5,0.5,0.5);
glTexCoord2f(0.0f, 0.0f);
glVertex2f(-1.0f, -1.0f);
//Top Left
glColor3f(0.2,0.7,0);
glTexCoord2f(0.0f, 1.0f);
glVertex2f(-1.0f,1.0f);
//Top Right
glColor3f(0.9,0.1,0.5);
glTexCoord2f(1.0f, 1.0f);
glVertex2f(1.0f,1.0f);
//Bottom Right
glColor3f(0.6,0.6,0.6);
glTexCoord2f(1.0f, 0.0f);
glVertex2f(1.0f,-1.0f);
glEnd();
/*
glBegin(GL_TRIANGLES);
glColor3f(0,1,0.7);
glVertex3f(-1,0,0);
glColor3f(0,0.1,0.5);
glVertex3f(1,0,0);
glColor3f(0.9,0.1,0);
glVertex3f(0,1,0);
glEnd();
*/
}
void GLWidget::LoadGLTexture()
{
if (!QFormatImage.load("actual path to the file with .bmp format"))
{
QMessageBox::information(this,
"Error",
"Could not load image");
}
GLFormatImage
= QGLWidget::convertToGLFormat(QFormatImage
);
glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, GLFormatImage.width(), GLFormatImage.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, GLFormatImage.bits());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
#include "glwidget.h"
GLWidget::GLWidget(QWidget *parent) :
QGLWidget(parent)
{
}
void GLWidget::initializeGL()
{
glEnable(GL_TEXTURE_2D);
glClearColor(1,1,0.5,1);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
}
//Setup viewport, projection etc...
void GLWidget::resizeGL(int w, int h)
{
if (h == 0)
{
h = 1;
}
}
//Draw the Scene
void GLWidget::paintGL() //corresponds to DrawGLScene
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
//glTranslatef(x, y, z)
//glTranslatef(0.0f,0.0f,-10.0f);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glBegin(GL_QUADS);
//Bottom Left
glColor3f(0.5,0.5,0.5);
glTexCoord2f(0.0f, 0.0f);
glVertex2f(-1.0f, -1.0f);
//Top Left
glColor3f(0.2,0.7,0);
glTexCoord2f(0.0f, 1.0f);
glVertex2f(-1.0f,1.0f);
//Top Right
glColor3f(0.9,0.1,0.5);
glTexCoord2f(1.0f, 1.0f);
glVertex2f(1.0f,1.0f);
//Bottom Right
glColor3f(0.6,0.6,0.6);
glTexCoord2f(1.0f, 0.0f);
glVertex2f(1.0f,-1.0f);
glEnd();
/*
glBegin(GL_TRIANGLES);
glColor3f(0,1,0.7);
glVertex3f(-1,0,0);
glColor3f(0,0.1,0.5);
glVertex3f(1,0,0);
glColor3f(0.9,0.1,0);
glVertex3f(0,1,0);
glEnd();
*/
}
void GLWidget::LoadGLTexture()
{
QImage GLFormatImage;
QImage QFormatImage;
if (!QFormatImage.load("actual path to the file with .bmp format"))
{
QMessageBox::information(this, "Error", "Could not load image");
}
GLFormatImage = QGLWidget::convertToGLFormat(QFormatImage);
glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, GLFormatImage.width(), GLFormatImage.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, GLFormatImage.bits());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
To copy to clipboard, switch view to plain text mode
Bookmarks