nuclear -9 Junior Poster in Training

I'm using fstream to read words from a file and I can't just read the whole word like so:

ifstream ob("file.txt");

    string word;

    ob >> word;

But I need to somehow specify to read 20 positions, even though there might be just spaces included. So I was trying to do something like this:

ifstream ob("file.txt");

    char word[20];, 20);

but when I cout this everything seem to be normal except the last element (word[20]) is some kind of a weird symbol, here's an example of what I mean:


I downloaded the latest version of this lib and now I get some exeptions not at the dealocattion/deletion, but when trying to allocate some pointers with "new". I get the "bad memory alloc".

Here's what I mean: Click Here

Different example I'm following: Click Here

nuclear -9 Junior Poster in Training

I'm using the Guichan lib and I was trying to run the "First application with Guichan, OpenGL and SDL" example, which is located here Click Here .

Everything was fine exept when I exit the program and delete all the pointers which were allocated with the "new" and because of this deletion I get an unhandled exeption/acces violation error. Note that I dont follow that example to the last line, but it should still be okay, I do the allocation in the constructor and deallocation in the destructor etc. I noticed that the same happens even if I run the example program to the last line.

Error: Click Here
(When I dont delete the pointers which were allocoted with "new", like its shown in the example, everything is just fine, not to mention the memory leak.)

Forgot to add this in a previous post. In my program I'm using SDL and OpenGL libs, so maybe GLUT or something similar that works with OpenGL contain some widget-like tools to use?

The compiler i use is "Visual c++ Express". I'll take a look at using the things you mentioned, though I dont think C# would work alongside my C++ code, would it? Though I see why it would be a good choice for something like this.

nuclear -9 Junior Poster in Training

I need to use forms, widgets etc. in my program which already takes care of creating a window and such. So the question is, would it be okay to use Windows lib to add the needed features, such as a form with a few widgets without any errors, memory leaks and such, cuz if I recall corretctly, when creating a window using Windows lib you would need to do some things to clean everything up afterwards, does the same apply to what I want to do (just for forms, widgets)?

nuclear -9 Junior Poster in Training

To be specific I'm trying to implement this into a small game. What I'm thinking of is having a base/default class for derived objects such as player, enemies, tiles and so on and later the derived classes would inherit this base class and add whatever is needed depending on the object.

Right now the base class contains all the basic variables needed and all the basic virtual functions. I'm thinking of making that the base class would have a constructor and parameters to initialize all the default variables and the derived class would add anything if needed in its own constructor, though this would mean I would have to add all the basic parameters which I would use in the base class constructor for initialization to the derived class constructor by using such syntax: classB(int x) : classA(x) and I think it's a bit too much work, I would like for a more automatic method.

Anyways, sorry for a long and hard to understand post, I would like some tips on how I should design such things. Posting some code below just clearance:

class Object
    fRect box_obj;
    float xVel, yVel, maxVel;
    float speed;
    std::string surfaceName;
    World* world_ptr;
    b2Body* body;
    Surface* sur_obj;
    Rotation* rot_pnt;
    virtual ~Object(); //Virtual methods defined in the .cpp file
    virtual void move();
    virtual void show();
    void set_angle();

And the Player:

#include "Object.h"

class Player : public Object
    Player(fRect fr_obj, World* bWorld, Surface* sur, std::string surName, bool isDynamic = false, bool rotatable ...

Nevermind, I've got it to work :) .

Oh my mistake, it seems that you were right about freeing the "rot" surface, since the "surface[0]" holds the adress of it later so if I free the "rot" surface, the "surface[0]" can't display anything.
The other thing I noticed that if I use a completely black painted surface and do everything correct, it doesnt't display the surface because it automatically makes the black color transparent, so if anyone has this problem just recolor the surface to some other color.

Anyways, thanks for your help.

The other thing that I need info on is using the rotozoomSurface() function inside my game loop, it seems if i predefine the surface's angle before the loop it rotates correctly, but if I use the function inside the loop and try to update the rotation every time, I get an unhandled exeption or a breakpoint.

This was just a small part of the code. I can free the "rot" surface because the "surface[0]" already takes the rotated surface before I delete it. Like I've said, I'm using SDL for quite some time, I know how to blit properly and stuff like that, the thing is that after I use the rotation function on my surface it dissapears.

nuclear -9 Junior Poster in Training

So I was trying out SDL_gfx lib and tryed using the rotozoomSurface() Click Here which should've rotated my surface at runtime, but it seems that whenever I do that my surface turns invisible. It doesn't matter if I predefine the rotation or use it at runtime, the same happens, I've tryed using the other rotation functions, still the same. Any info on this?

SDL_Surface* rot = rotozoomSurface(surface[0], 10, 1, 0);
surface[0] = rot;

Later I blit the surface[0] as usual. Note that without the code above the surface blits perfectly.

nuclear -9 Junior Poster in Training

Maybe I'm just missing something but I was thinking what do you call something like a Windows Form Application in Visual Studio where you can drag and drop and stuff like that. Do you call that an API or SDK or GUI or something else?

By the way, as I understand that Windows Form Application that I'm talking about is actually Visual Basic, correct me if I'm wrong. And if it possible to create applications by mostly drag and droping why use something like Win32 API?

I can agree that i have very little knowledge, i understood that when i was writing that list. To think that i thought i had a decent ammount of it but it was just that i never really thought about it. Anyway, thanks for those suggestions about open-source and GSoC, i will certainly take a look.

nuclear -9 Junior Poster in Training

I have no working experience but i do have some knowledge in programming and web development. Note that i cant work at a company or such right now so i think freelancing is the best choise for me. I think it's much better to list what kind of projects and such i've done in the past:

Some games using libs like SDL,
Started out with opengl,
Some simple Win32 API apps like String/Bit/Hex encoder/decoder
Some web development with PHP/HTML/CSS/JQUERY, making a few basic webs for myself and editing templates to make it look how i wanted to.

And of course i'm ready and able to learn and i like to do it mainly while working on projects, so my question is:

Can i start making money, even very little from this? I've looked around some jobs on Freelancer websites but there's a lot of competinion and some projects seem a bit hard.

I enjoyed the read and i can see what you mean, also i agree with thines01 that ""

all languages serve a particular purpose (or were created to solve a particular problem)

and i think that theres a lot to discuss about this, anyhow, thanks for interesting posts.

nuclear -9 Junior Poster in Training

I had this talk with a friend a while back and now i remmember that he said that C# is like a newer version of C++, but i think thats not correct, since C, C++, C# is kinda all oriented in this or that, what do you guys think of it?

Thanks for clearing this out for me.

I cant believe i havent though about it, i guess its a LOT better to just translate everything when i want to move around the world then doing i to every object seperatly, but maybe theres more regarding my quostion.

nuclear -9 Junior Poster in Training

I was just wondering why do we exactly call glTranste command if its possible just to increase objects x, y or z. And its even stated in this tutorial: that its even faster to only use Vertex3f() instead of resetting the Modelview Matrix.

Anyways, maybe its just something particular in this tutorial why we do exactly that or something similar, but i would like to know more.

nuclear -9 Junior Poster in Training

Just wanted to know if we need to texture map the texture on the model with code or is it better to just import a model with textures already on him? (considering its even possible)

nuclear -9 Junior Poster in Training

So i was simply following one of the opengl tutorials -

So everything works completely fine except one thing, when i load in textures with SOIL lib its not completely correct, but with GLAUX lib it works just fine but i dont prefer using GLAUX. Here is what i mean:

with GLAUX -
with SOIL -

Texture loading code with GLAUX (Dont mind the different filtering here):

AUX_RGBImageRec *LoadBMP(char *Filename)                // Loads A Bitmap Image
    FILE *File=NULL;                                // File Handle

    if (!Filename)                                  // Make Sure A Filename Was Given
            return NULL;                            // If Not Return NULL

    File=fopen(Filename,"r");                       // Check To See If The File Exists

    if (File)                                       // Does The File Exist?
            fclose(File);                           // Close The Handle
            return auxDIBImageLoad(Filename);       // Load The Bitmap And Return A Pointer
    return NULL;                                    // If Load Failed Return NULL

int LoadGLTextures()                                    // Load Bitmaps And Convert To Textures
    int Status=FALSE;                               // Status Indicator

    AUX_RGBImageRec *TextureImage[1];               // Create Storage Space For The Texture

    memset(TextureImage,0,sizeof(void *)*1);        // Set The Pointer To NULL

    // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
    if (TextureImage[0]=LoadBMP("Data/Mud.bmp"))
            Status=TRUE;                            // Set The Status To TRUE

            glGenTextures(3, &texture[0]);          // Create Three Textures

            // Create Nearest Filtered Texture
            glBindTexture(GL_TEXTURE_2D, texture[0]);
            glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

            // Create Linear Filtered Texture
            glBindTexture(GL_TEXTURE_2D, texture[1]);
            glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

            // Create MipMapped Texture
            glBindTexture(GL_TEXTURE_2D, texture[2]);
            gluBuild2DMipmaps(GL_TEXTURE_2D, 3, ...

Awesome! Thanks to you i finally realized how those stars worked, the little cordinate system helped to understand too. Even though i was very close back then but now i see how the translation remains in effect relative to the Tilt rotation to make an illusion that we are able to move up or down. Thanks man :)

Dont want to create a new threat for it so i would like to ask a few a simple question but i think it may help me to understand opengl better:

1.When we do transformations (translate, rotate, scale), we only move the whole scene, but the camera always stays in the same place, right?

2.In the tutorial that we were talking about, i tilted the scene, did everything i needed, reverted everything back and yet when i run the program i increase or decrease Tilt and it looks like we are moving around even though its rotation should be 0. I get why translation remains in effect, but not rotation.

3.If i do this:

glRotatef(star[loop].angle,0.0f,1.0f,0.0f); // Rotate To The Current Stars Angle
glTranslatef(star[loop].dist,0.0f,0.0f);    // Move Forward On The X Plane

do i need to imagine as if the whole scene was tilted along the y axis relative to the current star? Or i have to imagine as if the rotation was only made on that one star? i think the first one would be correct, since we load the identity matrix and do it again and stuff...

So yeah, is it normal that i ask so much since i can see that this is one of the harder opengl concepts and want to grasp it as better as i can, i assume that knowhing the math behind it is the key?

So, i was reading around how everything works (translate, rotate, scale, matrices etc.) and now i know that if we do this for example:

glRotatef(star[loop].angle, 0.0f, 1.0f, 0.0f);
glTranslatef(star[loop].dist, 0.0f, 0.0f);

The Translation will come first and the Rotation second, in reverse order. But before knowing this i figured that we rotate the object to face a certain direction first and then move it into that direction. But now when i think it actually does everything in reverse order these lines dont make much sense.

Aside from that its still kinda confusing with rotating everything and then rotating everything back but the translations still remaining in effect and a bunch of other stuff, but it is satisfying when one gets a hang of it :)

Thanks for a qucik reply. Yes, i think i might need to try doing different variations and stuff with rotation. Theres one more thing i would like to ask:

for (loop = 0; loop < num; loop++) {
    glTranslatef(0.0f, 0.0f, zoom);
    glRotatef(tilt, 1.0f, 0.0f, 0.0f);

    glRotatef(star[loop].angle, 0.0f, 1.0f, 0.0f);
    glTranslatef(star[loop].dist, 0.0f, 0.0f);

    glRotatef(-star[loop].angle, 0.0f, 1.0f, 0.0f);
    glRotatef(-tilt, 1.0f, 0.0f, 0.0f);

The part about "why 90" i meant that i dont get how this works, as in like in the code above. We rotate everything on the x axis by 90 (tilt=90), then we rotate the star[loop].angle ("angle" keeps increasing), but later we just undo it all with the last 2 lines. To my understandment the object should get back to the way it was at the start but it doesnt.

Thanks for the link. But it explains and shows the way i understand it, maybe im missing something or the guy in the tutorial made a mistake.

nuclear -9 Junior Poster in Training

It seems that i dont fully comprehend how rotation works. So leys say i have a cube and i do this:

x = 90.0f;
rotatef(x, 1.0f, 0.0f, 0.0f);

Notice that my code here may be not all correct, its like that just to symbolize what i mean.

So by doing that i would be facing the Top of the cube. But in this tutorial:
it states that by doing something like that, its like rotating the whole room so now X axis goes out or into the screen and Z axis is right or left. So its basically the part i dont get, like the guy in tutorial explains, why does the room rotate to the right side? For better understanding this a part from the tutorial:

int DrawGLScene(GLvoid)                     // Here's Where We Do All The Drawing

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glBindTexture(GL_TEXTURE_2D, texture[0]); // Select Our Texture

for (loop=0; loop<num; loop++)               // Loop Through All The Stars
    glLoadIdentity();               // Reset The View Before We Draw Each Star
    glTranslatef(0.0f,0.0f,zoom);           // Zoom Into The Screen (Using The Value In 'zoom')
    glRotatef(tilt,1.0f,0.0f,0.0f);         // Tilt The View (Using The Value In 'tilt')

"Now we move the star. The star starts off in the middle of the screen. The first thing we do is spin the scene on the x axis. If we spin 90 degrees, the x axis will no longer run left to right, it will run into and out of the screen. ...

Thanks for a quick reply, what i wanted to know is clear now and will do as you suggested to see the difference.

What i wanted to do was to make 3 same textures and see the difference between GL_LINEAR, GL_NEAREST and so on.
So what i did was (after loading the image into texture[0]):

texture[1] = texture[0];
texture[2] = texture[0];

And now i have a couple of questions:

  1. Is it a decently rational way of doing it? depending that i only want to see the diffrence.
  2. If i do this first:

    glBindTexture(GL_TEXTURE_2D, texture[0]);

and then do texture[1] = texture[0], does what i did before go into texture[1] aswell?
If yes, then i guess i could simply overwrite something else on texture[1] but the thing
is that i want to make sure to know all the details if these any more.

Oh and is it normal that i cant see the difference? maybe it just depends on the image, any suggestions what i could use to see the difference decently well?

nuclear -9 Junior Poster in Training

Straight to the point, I am using SOIL ( library to upload images into OpenGl. Loading textures works fine but there is this thing i dont fully comprehend.

Lets say I load an image into OpenGL via SOIL and I want to reuse the same image over few other textures so I would not load any more images to save memory. So without SOIL I would do something like this:

glGenTextures(3, &texture[0]);

thus generating 3 textures from 1 image i uploaded into texture[0]. But with SOIL to upload an image I need to use this:

texture[0] = SOIL_load_OGL_texture(

So I have texture[1] and texture[2] and I want to copy over the same texture withouth reloading anything again but dont have a full idea how to do that, in SOIL header file it states something like:

Passed in as reuse_texture_ID, will cause SOIL to
register a new texture ID using glGenTextures().
If the value passed into reuse_texture_ID > 0 then
SOIL will just re-use that texture ID (great for
reloading image assets in-game!)


but like I've said, I cant fully understand how the code would look like I described.

P.S im following this tut,_lighting_&_keyboard_control/15002/
Note that in this tutorial he still uses the old image loading method, im using the one he formed in his previous tutorial.