PastaPojken's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
Members
Active Posts:
16 (0.02 per day)
Joined:
27-October 12
Profile Views:
282
Last Active:
User is offline Oct 03 2013 11:42 AM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   PastaPojken has not set their status

Posts I've Made

  1. In Topic: C++/SDL/OpenGL crash on windows

    Posted 30 Jan 2013

    I found the error, it's in the "loadtexture" function, it appears to be caused by GL_UNSIGNED_BYTE. Thanks for the help
  2. In Topic: C++/SDL/OpenGL crash on windows

    Posted 30 Jan 2013

    View PostButchDean, on 29 January 2013 - 02:57 PM, said:

    Firstly, you are coding a C++ program like it's C. Secondly, you have no code to handle when resources are not allocated successfully.

    Next, you need to run a debug session to pinpoint the precise location of the crash - not just dump all your code here expecting us to fix your work.


    Well, I have no code that handles the resources if they are not allocated succefully because I've never had any problems with that (and it's not what is causing the crash...) so I never felt that I actually needed one. The game was originally written using only SDL but then I decided to use OpenGL for drawing. Since then I've not been able to make it work on windows.

    Today I discovered that somehow the debugger in dev-cpp isn't working properly. Anyway I tried debugging with VC++, the effect is the same (white window) except that it doesn't crash. The debugger itself isn't outputting any errors.

    I'm sorry for just "dumping" the code but I really don't understand what I am doing wrong.
  3. In Topic: C++/SDL/OpenGL crash on windows

    Posted 29 Jan 2013

    I noticed that I accidentally left some code that isn't supposed to be there in the "Init.h" file,
    here is the correct version:

    #ifdef __linux__
    #include "SDL/SDL.h"
    #include "SDL/SDL_image.h"
    #include "SDL/SDL_ttf.h"
    #include "SDL/SDL_opengl.h"
    #include "SDL/SDL_mixer.h"
    
    
    #else
    #include "SDL.h"
    #include "SDL_opengl.h"
    #include "SDL_image.h"
    #include "SDL_ttf.h"
    #include "SDL_mixer.h"
    #endif
    
    #include <stdio.h>
    #include <string>
    #include <cstring>
    #include <fstream>
    #include <iostream>
    #include <time.h>
    #include <cmath>
    
    
    
    using namespace std;
    
    int background;
    int console;
    GLuint glmessage;
    GLuint glmessage2;
    GLuint glmessage3;
    SDL_Surface *message=NULL;
    SDL_Surface *message2=NULL;
    SDL_Surface *message3=NULL;
    SDL_Surface *text=NULL;
    int gltext;
    int screen;
    int overlay;
    int shadow;
    int m_flash;
    
    char pars[100];
    
    
    int loop=0;
    bool showtext=true;
    bool abswitch = false;
    bool abcswitch = false;
    bool holdd=false;
    
    bool b_key=false;
    bool pl_key=false;
    bool y_key=false;
    bool lb_key=false;
    bool g_key=false;
    
    bool mess1=false;
    bool mess2=false;
    bool mess3=false;
    
    bool r1_doorun=false;
    bool r3_doorun=false;
    bool r4_doorun=false;
    bool r6_doorun=false;
    
    int r1_doorop=0;
    int r3_doorop=0;
    int r4_doorop=0;
    int r6_doorop=0;
    
    
    bool light=false;
    bool m_flashl=false;
    int m_flashl_=1; //flashlight
    
    int we_door=0; //west or east door chose 0=inactive 1=west 2=east 3=north 4=south
    int k_roomin=0; // 0=no key of the room you are in 1=you have the key of the room you're in
    
    bool keys[323]={false};
    
    int music_v=32;
    int music_v2;
    
    int music_vm=0;
    
    int m_x=0, m_y=0;
    
    //Quit flag
    bool quit = false;
    
    //The music that will be played
    Mix_Music *music;
    
    //The storage strings for console instrucitions
    string str;
    string str2;
    string str3;
    
    
    string a;
    string b;
    string c;
    
    string room_look;
    
    
    //The event structure
    SDL_Event event;
    
    //The font
    TTF_Font *font;
    TTF_Font *fontv2;
    
    
    //The color of the font
    SDL_Color textColor = { 255, 0, 0};
    
    
    
    void RenderText(const TTF_Font *Font, const GLubyte& R, const GLubyte& G, const GLubyte& B,
                    const double& X, const double& Y, const double& Z,  const std::string& Text)
    {
    	/*Create some variables.*/
    	SDL_Color Color = {R, G, B};
    	SDL_Surface *Message = TTF_RenderText_Blended(const_cast<TTF_Font*>(Font), Text.c_str(), Color);
    	unsigned Texture = 0;
        
    	/*Generate an OpenGL 2D texture from the SDL_Surface*.*/
    	glGenTextures(1, &Texture);
    	glBindTexture(GL_TEXTURE_2D, Texture);
        
    	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        
    	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Message->w, Message->h, 0, GL_BGRA,
    	             GL_UNSIGNED_BYTE, Message->pixels);
        
    	/*Draw this texture on a quad with the given xyz coordinates.*/
    	glBegin(GL_QUADS);
        glTexCoord2d(0, 0); glVertex3d(X, Y, Z);
        glTexCoord2d(1, 0); glVertex3d(X+Message->w, Y, Z);
        glTexCoord2d(1, 1); glVertex3d(X+Message->w, Y+Message->h, Z);
        glTexCoord2d(0, 1); glVertex3d(X, Y+Message->h, Z);
    	glEnd();
        
    	/*Clean up.*/
    	glDeleteTextures(1, &Texture);
    	SDL_FreeSurface(Message);
    }
    
    
    void FillRect(int x, int y, int w, int h, int c1, int c2, int c3) {
        int f_rect=0;
        glBindTexture(GL_TEXTURE_2D, f_rect);
        glColor3f ((double)c1/255, (double)c2/255, (double)c3/255);
        glBegin(GL_QUADS);
        glTexCoord2f(0,0); glVertex2f(x, y-h);
        glTexCoord2f(1,0); glVertex2f(x+w,y-h);
        glTexCoord2f(1,1); glVertex2f(x+w, y);
        glTexCoord2f(0,1); glVertex2f(x, y);
        glEnd();
        SDL_GL_SwapBuffers();
    }
    
    
    int loadTexture(std::string fileName){
        SDL_Surface *image=IMG_Load(fileName.c_str());
        SDL_DisplayFormatAlpha(image);
        unsigned object(0);
        glGenTextures(1,&object);
        glBindTexture(GL_TEXTURE_2D,object);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
        glTexImage2D(GL_TEXTURE_2D,0, GL_RGBA,image->w,image ->h,0, GL_BGRA_EXT,GL_UNSIGNED_BYTE,image->pixels);
        SDL_FreeSurface(image);
        return object;
    }
    
    void init(){
        
        srand(time(NULL));
        
        /* Initialization */
        SDL_InitSubSystem(SDL_INIT_AUDIO);
        
        SDL_EnableKeyRepeat(250, 100);
        
        //Initialize SDL_mixer
        Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 4096 );
        
        TTF_Init();
        
        music = Mix_LoadMUS( "LT.ogg" );
        //Open the font
        font = TTF_OpenFont( "menlo.ttc", 12 );
        fontv2 = TTF_OpenFont( "menlo.ttc", 20 );
        
        
        SDL_EnableUNICODE( SDL_ENABLE );
            
        glClearColor(0.0,0.0,0.0,0.0);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0.0,1024,740,1.0, 0.0,1.0);
        glEnable(GL_BLEND);
        glEnable(GL_TEXTURE_2D);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        background=loadTexture("Scalpel.png");
        console=loadTexture("console.png");
        shadow=loadTexture("BBB.png");
    
    }
    
    
    void draw(){
        glClear(GL_COLOR_BUFFER_BIT);
        glBindTexture(GL_TEXTURE_2D,background);
        //glColor4f ((double)255/255, (double)255/255, (double)255/255, (double)100/255);
        glColor3f(1.0f, 1.0f, 1.0f);
        glBegin(GL_QUADS);
        glTexCoord2f(0,0); glVertex2f(0,0);
        glTexCoord2f(1,0); glVertex2f(1024,0);
        glTexCoord2f(1,1); glVertex2f(1024,600);
        glTexCoord2f(0,1); glVertex2f(0,600);
        glEnd();
        
        glBindTexture(GL_TEXTURE_2D, overlay);
        glColor4f ((double)0/255, (double)0/255, (double)0/255, 0.80f);
        glBegin(GL_QUADS);
        glTexCoord2f(0,0); glVertex2f(0,0);
        glTexCoord2f(1,0); glVertex2f(1024,0);
        glTexCoord2f(1,1); glVertex2f(1024,740);
        glTexCoord2f(0,1); glVertex2f(0,740);
        glEnd();
        
    
        
            if (m_flashl==true){
         glBindTexture(GL_TEXTURE_2D, shadow);
         //glColor4f ((double)255/255, (double)255/255, (double)255/255, 0.25f);
         //glColor3f(1.0f, 1.0f, 1.0f);
            glColor4f(1, 1, 1, 0.1f);
         glBegin(GL_QUADS);
         glTexCoord2f(0,0); glVertex2f(m_x-150, m_y-150);
         glTexCoord2f(1,0); glVertex2f(m_x+150, m_y-150);
         glTexCoord2f(1,1); glVertex2f(m_x+150, m_y+150);
         glTexCoord2f(0,1); glVertex2f(m_x-150, m_y+150);
         glEnd();}
        
        glBindTexture(GL_TEXTURE_2D, console);
        glColor3f(1.0f, 1.0f, 1.0f);
        glBegin(GL_QUADS);
        glTexCoord2f(0,0); glVertex2f(0,595);
        glTexCoord2f(1,0); glVertex2f(1024,595);
        glTexCoord2f(1,1); glVertex2f(1024,595+156);
        glTexCoord2f(0,1); glVertex2f(0,595+156);
        glEnd();
        
        if (mess1==true)
            RenderText(font, 255, 0, 0, 35, 630+12, NULL, a.c_str());
        if (mess2==true)
            RenderText(font, 255, 0, 0, 35, 646+12, NULL, b.c_str());
        if (mess3==true)
            RenderText(font, 255, 0, 0, 35, 662+12, NULL, c.c_str());
        
        if (str.length()!=0){
            RenderText(font, 255, 0, 0, 35, 694+12, NULL, str.c_str());
            
        }
        
        glFlush();
        SDL_GL_SwapBuffers();
    }
    
    
  4. In Topic: C++/SDL "fog of war" effect

    Posted 8 Jan 2013

    View Post#define, on 07 January 2013 - 12:05 PM, said:

    The poster is using the alpha channel at pixel-level. SDL can use surface-level alpha and pixel-level alpha.

    Here is a surface level tutorial to give you an idea.

    Alpha Blending


    Thank you!!! :D That really helps! :)
  5. In Topic: C++/SDL "fog of war" effect

    Posted 4 Jan 2013

    View Postmodi123_1, on 04 January 2013 - 03:38 PM, said:

    So.. what do you want people to help you with?


    Sorry if I wasn't clear, I would really appreciate if someone could give me any hints or maybe explain in a more clearly way what the guy in the link is doing :)

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Click here to e-mail me

Friends

PastaPojken hasn't added any friends yet.

Comments

Page 1 of 1
  1. Photo

    darktrooper47 Icon

    08 Jan 2013 - 10:15
    I know this has little to do with C++ but I need some help with library basic. The problem is that I cant get a textbox to be combine to a variable. Can you help?
Page 1 of 1