Qt MapEditor[HELP]
Posted: Fri Jul 23, 2010 8:46 pm
ok i went with opengl instead of sfml and everything was going great and rendering fine until i added the second window and now only the window i just added renders the image and the other window dosent... no matter what! even if i load a different image for it it just renders white squares. would this have anything to do with qt. i have a QMainWindow and 2 QGLWidgets ( i made classes that inherit from them ) the glWidgets are childern windows of the main window. do you know why this is happening???? ill post my image code
if you want more code i can post it, Thanks for looking
if i cant get this to work im going back to win32 to finish this project but i love Qt sooooo much
Code: Select all
#ifndef IMAGE_H
#define IMAGE_H
#include "Windows.h"
#include <QImage>
#include <gl/gl.h>
struct TileRect;
class Image
{
public:
Image(QString name);
Image();
~Image();
void Load(QString name);
void Render();
QRect& GetRect() const;
QString& GetImageName() const;
int GetX() const;
int GetY() const;
void SetClip(int x, int y, int w = 32, int h = 32)
{
m_clipRect.setRect(x,y,w,h);
m_position.setRect(x,y,w,h);
}
void SetPosition(int x, int y);
private:
QRect m_clipRect;
QRect m_position;
GLuint m_texture;
QImage image;
};
#endif // IMAGE_H
Code: Select all
#include "Image.h"
#include <QColor>
#include <QRgb>
#include <QFile>
#include <QGLWidget>
Image::Image(QString name)
{
image.createMaskFromColor(QColor(255, 0, 255).rgb());
Load(name);
}
Image::Image()
{
image.createMaskFromColor(QColor(255, 0, 255).rgb());
}
Image::~Image()
{
if(glIsTexture(m_texture)) glDeleteTextures(1, &m_texture);
}
void Image::Load(QString name)
{
QImage temp;
if(!temp.load(name))
{
QFile file("log.txt"); file.open(QIODevice::WriteOnly); file.write("not loaded"); file.close();
}
image = QGLWidget::convertToGLFormat(temp);
glGenTextures(1, &m_texture);
glBindTexture(GL_TEXTURE_2D, m_texture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D,0,4,image.width(),image.height(),0, GL_RGBA, GL_UNSIGNED_BYTE, image.bits());
m_clipRect.setCoords(0, 0, image.width(), image.height());
m_clipRect.setWidth(image.width());
m_clipRect.setHeight(image.height());
m_clipRect.setX(0);
m_clipRect.setY(0);
m_position.setCoords(0, 0, image.width(), image.height());
m_position.setWidth(image.width());
m_position.setHeight(image.height());
}
int Image::GetX() const
{
return m_position.x();
}
int Image::GetY() const
{
return m_position.y();
}
void Image::Render()
{
//glClearColor(0.f, 1.f, 0.f, 0.f);
glPushMatrix();
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_texture);
// glTranslatef((float)GetX(),(float)GetY(),0);
///glColor4f(1.0f,1.0f,1.0f,Alpha);
/// @todo fix the Render function to work... the code between glBegin and glEnd is broken :(
/// COMPLETE
glBegin(GL_QUADS);
/// @todo do the Vertices
/// COMPLETE
glTexCoord2f(m_clipRect.x() / image.width(), m_clipRect.y() / image.height() );
glVertex2f(m_position.left(),m_position.top());
glTexCoord2f((m_clipRect.x() + m_clipRect.width() ) / image.width(),m_clipRect.y() / image.width() );
glVertex2f(m_position.left(), m_position.bottom());
glTexCoord2f((m_clipRect.x() + m_clipRect.width() ) / image.width(),(m_clipRect.y() + m_clipRect.height()) / image.height());
glVertex2f(m_position.right() ,m_position.bottom());
glTexCoord2f(m_clipRect.x() / image.width(), (m_clipRect.y() + m_clipRect.height()) / image.height());
glVertex2f(m_position.right() ,m_position.top() );
glEnd();
glPopMatrix();
}
void Image::SetPosition(int x, int y)
{
m_position.moveTopLeft(QPoint(x,y));
//m_position.setCoords(x, y, x + m_position.width(), y - m_position.height());
}
if you want more code i can post it, Thanks for looking
if i cant get this to work im going back to win32 to finish this project but i love Qt sooooo much