void MyGLWidget::loadTextures() { QImage image[2]; if (image[0].load(":/bg.bmp") && image[1].load(":/reflect.bmp")) { convertToGLFormat(image[0]); convertToGLFormat(image[1]); /* Create The Texture */ glGenTextures( NUM_TEXTURES, &texture[0] ); for(int loop = 0; loop <= 1; loop++ ) { /* Create Nearest Filtered Texture */ glBindTexture( GL_TEXTURE_2D, texture[loop] ); /* Gen Tex 0 And 1 */ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST ); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, image[loop].width(), image[loop].height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, image[loop].bits() ); /* Create Linear Filtered Texture */ glBindTexture( GL_TEXTURE_2D, texture[loop+2] ); /* Gen Tex 2 And 3 */ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, image[loop].width(), image[loop].height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, image[loop].bits() ); /* Create MipMapped Texture */ glBindTexture( GL_TEXTURE_2D, texture[loop+4] ); /* Gen Tex 4 and 5 */ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST ); gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGBA, image[loop].width(), image[loop].height(), GL_RGBA, GL_UNSIGNED_BYTE, image[loop].bits() ); } } }
void MyGLWidget::loadTextures() { QImage image; if (image.load(":/Crate.bmp")) { image = convertToGLFormat(image); glGenTextures(3, texture); // Create Nearest Filtered Texture glBindTexture(GL_TEXTURE_2D, texture[0]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width(), image.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, image.bits()); // Create Linear Filtered Texture glBindTexture(GL_TEXTURE_2D, texture[1]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width(), image.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, image.bits()); // Create MipMapped Texture glBindTexture(GL_TEXTURE_2D, texture[2]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, image.width(), image.height(), GL_RGBA, GL_UNSIGNED_BYTE, image.bits()); } }
////////////////////////////////////////////////makeTextures/////////////////////////////////////////////////////////////// void GLViewer::makeObjects() { // texture QImage tex; tex = convertToGLFormat(*g_texture_image_); glGenTextures(1, &g_texture_id_); glBindTexture(GL_TEXTURE_2D, g_texture_id_); glTexImage2D(GL_TEXTURE_2D, 0, 3, tex.width(), tex.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, tex.bits()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glewInit(); glGenVertexArrays(1, &arrayIndex); enum{ Verices, TexCoords, Colors, Elements, NumAttris }; GLuint buffers[NumAttris]; GLfloat *colors = new GLfloat[g_element_num_[0] * 3]; for (int i = 0; i < g_element_num_[0]; i++) { colors[i * 3 + 0] = (GLfloat)0.5; colors[i * 3 + 1] = (GLfloat)0.5; colors[i * 3 + 2] = (GLfloat)0.5; } NumElements = (GLsizei)g_element_num_[1] * 3; glBindVertexArray(arrayIndex); glGenBuffers(NumAttris, buffers); //VERTEX glBindBuffer(GL_ARRAY_BUFFER, buffers[Verices]); glBufferData(GL_ARRAY_BUFFER, g_element_num_[0] * 3 * sizeof(GLfloat), g_vertices_, GL_STATIC_DRAW); glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0)); glEnableClientState(GL_VERTEX_ARRAY); // COLOR glBindBuffer(GL_ARRAY_BUFFER, buffers[Colors]); glBufferData(GL_ARRAY_BUFFER, g_element_num_[0] * 3 * sizeof(GLfloat), colors, GL_STATIC_DRAW); glColorPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0)); glEnableClientState(GL_COLOR_ARRAY); // TEXTURE COORDS for (int i = 0; i < g_element_num_[0]; i++) { g_texture_coords_[i * 2 + 1] = 1 - g_texture_coords_[i * 2 + 1]; } glBindBuffer(GL_ARRAY_BUFFER, buffers[TexCoords]); glBufferData(GL_ARRAY_BUFFER, g_element_num_[0] * 2 * sizeof(GLfloat), g_texture_coords_, GL_STATIC_DRAW); glTexCoordPointer(2, GL_FLOAT, 0, BUFFER_OFFSET(0)); glEnableClientState(GL_TEXTURE_COORD_ARRAY); //Face ELEMENT glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[Elements]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, g_element_num_[1] * 3 * sizeof(GLuint),g_facets_, GL_STATIC_DRAW); }
void PresentationKB::endOfShow() { QPixmap pix(512, 512); pix.fill(Qt::black); QFont fn(font()); fn.setPointSize(fn.pointSize() + 10); fn.setBold(true); QPainter p(&pix); p.setPen(Qt::white); p.setFont(fn); p.drawText(20, 50, i18n("SlideShow Completed")); p.drawText(20, 100, i18n("Click to Exit...")); p.end(); QImage image = pix.toImage(); QImage t = convertToGLFormat(image); GLuint tex; /* create the texture */ glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); /* actually generate the texture */ glTexImage2D(GL_TEXTURE_2D, 0, 3, t.width(), t.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, t.bits()); /* enable linear filtering */ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); /* paint the texture */ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glBindTexture(GL_TEXTURE_2D, tex); glBegin(GL_QUADS); { glColor4f(1.0, 1.0, 1.0, 1.0); glTexCoord2f(0, 0); glVertex3f(-1.0, -1.0, 0); glTexCoord2f(1, 0); glVertex3f(1.0, -1.0, 0); glTexCoord2f(1, 1); glVertex3f(1.0, 1.0, 0); glTexCoord2f(0, 1); glVertex3f(-1.0, 1.0, 0); } glEnd(); d->showingEnd = true; }
StelTexture::GLData StelTexture::imageToGLData(const QImage &image) { GLData ret = GLData(); if (image.isNull()) return ret; ret.width = image.width(); ret.height = image.height(); ret.data = convertToGLFormat(image, &ret.format, &ret.type); return ret; }
void Slideshow::loadTexture (QString filename) { logGLError("before loadTexture"); QImage t = convertToGLFormat( QPixmap (filename).toImage() ); if (t.width() > 2048 || t.height() > 2048) { // better downscale, old graphics cards don't do big textures t = t.scaled (2048, 2048, Qt::KeepAspectRatio); } logGLError("in convertToGLFormat"); inImage = t; setTexture (&t, 1); logGLError("in setTexture"); }
// Initialize OpenGL void GLWidget::initializeGL() { glShadeModel(GL_SMOOTH); // Enable smooth shading qglClearColor(Qt::black); // Set the clear color to a black background glClearDepth(1.0f); // Depth buffer setup glEnable(GL_DEPTH_TEST); // Enable depth testing glDepthFunc(GL_LEQUAL); // Set type of depth test glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really nice perspective calculations // Set up textures // Note: Because we need different texture filters, we cannot use Qt's bindTexture() // Qt automatically generates the most appropriate textures using available features in your setup // which means that Qt always generates mipmaps if your system supports them // We will use normal glBindTexture() etc. functions instead glEnable(GL_TEXTURE_2D); QImage img = convertToGLFormat(QImage(":/img/Crate.bmp")); glGenTextures(3, texture); // Texture using nearest filter glBindTexture(GL_TEXTURE_2D, texture[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 3, img.width(), img.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, img.bits()); // Texture using linear filter glBindTexture(GL_TEXTURE_2D, texture[1]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 3, img.width(), img.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, img.bits()); // Texture using mipmaps glBindTexture(GL_TEXTURE_2D, texture[2]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, img.width(), img.height(), GL_RGBA, GL_UNSIGNED_BYTE, img.bits()); // Set up lighting GLfloat ambLight[] = {0.3f, 0.3f, 0.3f, 1.0f}; GLfloat diffLight[] = {1.0f, 1.0f, 1.0f, 1.0f}; GLfloat lightPos[] = {0.0f, 0.0f, 2.0f, 1.0f}; glLightfv(GL_LIGHT1, GL_AMBIENT, ambLight); glLightfv(GL_LIGHT1, GL_DIFFUSE, diffLight); glLightfv(GL_LIGHT1, GL_POSITION, lightPos); glEnable(GL_LIGHT1); glEnable(GL_LIGHTING); }
void GLWidget::initializeGL() { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glShadeModel(GL_SMOOTH); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glEnable(GL_TEXTURE_2D); QImage img = convertToGLFormat(QImage("wall.jpg")); glGenTextures(1, texture); glBindTexture(GL_TEXTURE_2D, texture[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, img.width(), img.height(), GL_RGBA, GL_UNSIGNED_BYTE, img.bits()); glClearDepth(1.0f); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); }
void GLWidget::initializeGL(){ glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); glDepthFunc(GL_LEQUAL); glDepthRange(0.0f, 1.0f); //glClearColor(0.2,0.2,0.2,1); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations Camera.Position_Camera(0, 0.5f, 5, 0, 0.5f, 0, 0, 1, 0); QApplication::setOverrideCursor(QCursor(Qt::BlankCursor)); Auto = new MilkshapeModel(); // Memory To Hold The Model if ( Auto->loadModelData( "Auto.ms3d" ) == false ) // Loads The Model And Checks For Errors { //int ret = QMessageBox::warning(this, tr(""),tr("erro ao carregar modelo"), QMessageBox::Cancel); } // Carregando textura do pizo. glShadeModel(GL_SMOOTH); QImage img = convertToGLFormat(QImage(":/img/Concreto2.jpg")); glGenTextures(1, &texture[0]); glBindTexture( GL_TEXTURE_2D, texture[0] ); // Texture using mipmaps glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, img.width(), img.height(), GL_RGBA, GL_UNSIGNED_BYTE, img.bits()); QImage b; // carregando textura da caixa de madeira. if ( !b.load( ":/img/Crate.bmp")) { //qWarning( "Could not read image file, using single-color instead." ); b = QImage( 16, 16, QImage::Format_RGB888 ); b.fill( QColor(Qt::green).rgb() ); } img = convertToGLFormat(b); glGenTextures(1, &texture[1]); glBindTexture( GL_TEXTURE_2D, texture[1] ); glTexImage2D( GL_TEXTURE_2D, 0, 3, img.width(), img.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, img.bits() ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); //Luz avermelhada (sala com lava?) GLfloat ambientLight[] = {1.0f, 1.0f, 1.0f, 1.0f}; //Habilitamos a capacidade de iluminação glEnable(GL_LIGHTING); //Configuramos a OpenGL para utilizar como luz ambiente global //a iluminação definida por ambientLight[] glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight); }
void GLWidget::paintGL() { int i; QList<Point3D> points; QImage image; //Set backgroung glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); rotateCamera(); drawGround( 10.0f, 1.0f, 0); //Using stack of matrix glPushMatrix(); //Draw all objects glEnable(GL_TEXTURE_2D); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); //colors of glObject are replaced by texture. other - GL_REPLACE - combination glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); float refl; int shine; //need to draw pictures then objects //Drawing images for( i = 0; i < Scene::Instance().stub_objects().size(); i++) { //checking type of object - lense or picture LensObjectStub* n = dynamic_cast<LensObjectStub*>(Scene::Instance().stub_objects()[i]); if (!(n)) { shine = 10; refl = 0.5; //textures PictureObjectStub* picobj = (PictureObjectStub*)Scene::Instance().stub_objects()[i]; image = convertToGLFormat(picobj->image()); glTexImage2D(GL_TEXTURE_2D, 0, 3, (GLsizei)image.width(), (GLsizei)image.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, image.bits()); if (Scene::Instance().stub_objects()[i]->selected()) { glColor4f( 0.1, 0.1, 1.0, 1.0); } else { glColor4f( 1.0, 1.0, 1.0, 1.0); } float specref[] = { refl, refl, refl}; glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, specref); glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, shine); //0..128 - reflection points = Scene::Instance().stub_objects()[i]->getPoints(); //qDebug() << points; //Drawing pictures glBegin( GL_QUADS); //Draw normals for lighting TODO //glNormal3f( x, y ,z); glTexCoord2f(0, 1); glVertex3f( points[0].x, points[0].y, points[0].z); glTexCoord2f(1, 1); glVertex3f( points[1].x, points[1].y, points[1].z); glTexCoord2f(1, 0); glVertex3f( points[2].x, points[2].y, points[2].z); glTexCoord2f(0, 0); glVertex3f( points[3].x, points[3].y, points[3].z); glEnd(); } } //Drawing lenses for( i = 0; i < Scene::Instance().stub_objects().size(); i++) { //checking type of object - lense or picture LensObjectStub* n = dynamic_cast<LensObjectStub*>(Scene::Instance().stub_objects()[i]); if (n) { shine = 128; refl = 1.0; glEnable(GL_CULL_FACE); glCullFace(GL_FRONT); image = convertToGLFormat(n->heightMap1()); glTexImage2D(GL_TEXTURE_2D, 0, 3, (GLsizei)image.width(), (GLsizei)image.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, image.bits()); if (Scene::Instance().stub_objects()[i]->selected()) { glColor4f( 0.1, 0.1, 1.0, 0.5); } else { glColor4f( 1.0, 1.0, 1.0, 0.5); } float specref[] = { refl, refl, refl}; glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, specref); glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, shine); //0..128 - reflection points = Scene::Instance().stub_objects()[i]->getPoints(); //qDebug() << points; //Drawing pictures glBegin( GL_QUADS); //Draw normals for lighting TODO //glNormal3f( x, y ,z); glTexCoord2f(0, 1); glVertex3f( points[0].x, points[0].y, points[0].z); glTexCoord2f(1, 1); glVertex3f( points[1].x, points[1].y, points[1].z); glTexCoord2f(1, 0); glVertex3f( points[2].x, points[2].y, points[2].z); glTexCoord2f(0, 0); glVertex3f( points[3].x, points[3].y, points[3].z); glEnd(); //draw back with diff texture glCullFace(GL_BACK); image = convertToGLFormat(n->heightMap2()); glTexImage2D(GL_TEXTURE_2D, 0, 3, (GLsizei)image.width(), (GLsizei)image.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, image.bits()); glBegin( GL_QUADS); //Draw again wi other texture glTexCoord2f(0, 1); glVertex3f( points[0].x, points[0].y, points[0].z); glTexCoord2f(1, 1); glVertex3f( points[1].x, points[1].y, points[1].z); glTexCoord2f(1, 0); glVertex3f( points[2].x, points[2].y, points[2].z); glTexCoord2f(0, 0); glVertex3f( points[3].x, points[3].y, points[3].z); glEnd(); glCullFace(GL_FRONT_AND_BACK); glDisable(GL_CULL_FACE); } } /*glPushMatrix(); glBegin(GL_LINES); glVertex3f(8, -9, 5); glVertex3f(0, 0, 0); glEnd(); glPopMatrix();*/ glPopMatrix(); drawCamera(); //clear drawing command stack swapBuffers(); }
TexInfo GLWindow::loadImage( QImage * imgPtr ) { makeCurrent(); QImage image = convertToGLFormat( *imgPtr ); return loadImage( image.width(), image.height(), image.bits(), GL_RGBA ); }