Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


shawk08033

Member Since 16 Jul 2012
Offline Last Active May 28 2014 05:39 PM

Topics I've Started

Opengl qt

26 April 2014 - 03:09 PM

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;
}


Read text as a map in c++

20 January 2014 - 04:06 PM

Hi I have a class call map. 

#include "Map.h"
#include <fstream>
#include <ostream>
#include <istream>

Log spritelog("spritedebug.txt", false);
Map::Map()
{
Load();
spritelog << "Sprites are loaded" << std::endl;
}
void Map::Load()
{
    ifstream resources("resources.txt");
    std::string str;
    int i = 0;
    while (std::getline(resources, str))
    {
      UsedSprites[i] = new Sprite(0, 0, str);
      i++;
    }
    resources.close();
    delete resources;
    str = "";
    ifstream maptext("map.txt");
    i = 0;
    int y = 0;
    int x = 0;
    while(std::getline(maptext, str))
    {
        stringstream stream(str);
        string c = "";
        while(std::getline(stream,c, ','))
        {
          int n = atoi(c.c_str());
          MapSprite[x] = UsedSprites[n];
          MapSprite[x]->X = i*64;
          MapSprite[x]->Y = y*64;
          spritelog << n << "Loading into " << x << " at " << i*64 << "," << y*64 << std::endl;
          i++;
          x++;
        }
        y++;
        i = 0;
    }
    maptext.close();
    spritelog << "Loading " << x << " Sprites Into Map at " << y << " lines" << std::endl;
    delete UsedSprites;
    delete maptext;
}
void Map::Render()
{
    for(int i = 0; i < 34; i++)
    {
        MapSprite[i]->Render();
        spritelog << "Rended: " << i << "X: " << MapSprite[i]->X << " Y: " << MapSprite[i]->Y << std::endl;
    }
}


When I load this text file:

0,1,0,0,1
1,0,0,0,1
1,1,1,1,1
0,0,0,0,0
1,1,1,1,1
1,0,0,0,1
1,1,1,1,1
 
0 = green 1= grey
 
See attachments for debug info and screen shot.Attached File  helpc++.PNG   231.75KB   3 downloadsAttached File  spritedebug.txt   1.82KB   30 downloads
 
When is the x and y not the same as what I set it in Load() to what it renders at.

Making an optimized 3d mmo in open gl c++

04 April 2013 - 05:05 PM

I currently starting to make a mmorpg in c++ using opengl. How could I optimized it to run the best it can on integrated graphics but also take full advantage of top of line graphics card like a GTX 660 or higher.Would it been done directly in the way I code opengl or would it been done by changing the quality of the texture images?? 


Representing player classes in c++

21 September 2012 - 01:57 PM

What is the best way to represent player classes for an rpg game in c++

Rendering Engine For QT

22 July 2012 - 10:48 AM

Is there any open source cross platform rendering/graphics engine for qt

PARTNERS