Ok so first off, I've recently returned to C++, and I'm very new to both OpenGL, and Code::Blocks IDE (used to use Bloodshed Dev before) .. so please don't flame me if there's a basic solution to this

I'm trying to read a ".asc" file which has the vertices of a model I want to replicate using Glut (please don't mention assimp at the moment, because at my level all that just went over my head)

Anyways, I made a new project OpenGL in Code::Blocks, (I've installed freeglut so there's no problem there for sure), and basically when using the code below, the output I get is "0"

#include <GL/glut.h>
#include <stdlib.h>

using namespace std;

int main(int *argcp, char **argv)

    ifstream myfile("test.txt");

    return 0;

Which is the problem I'm facing. If I make an OpenGL project, I can't read even a basic text file, and when I make a basic empty project then I can read the file but glut doesn't work and I get errors saying "undefined reference to '_imp____glutInitWithExit@12' and such.

I'm pretty sure I must be doing something wrong, because something so basic shouldn't be so trivial. If anyone out here could help me bypass this simple obstacle, that would be great

Recommended Answers

All 2 Replies

Generally, if you cannot open a file that does exist, it's because you're not looking in the right place.

Start by replacing the filename with the complete path and see if that works. If it does, you know that your program is looking in the wrong place. How do you know that the working directory of your program is the same as the directory in which the file is? The working directory of your file will almost certinaly (since you're using an IDE) not be the project directory, and may not even be the directory the executable is in.

thank you Moschops, but i actually (kind of) found the solution after a little dabbling with Code Blocks
Fstream functions still don't work when I made an OpenGL project, so instead I used the empty project and manually linked all the glut/opengl directories, which allowed me to use both Fstream and Glut together

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.