I am VERY new to C ++ and Open GL, and I am trying to display 3D objects in a scene. it worked fine with one, but when I tried changing my code to add a second, my code regarding the HUD text showing the location of the camera started to give errors. The above error is shown and appears to be in the sstream (#include) file. I tried looking and asking for help, but I don’t understand anything. When I comment out the #include line and the code that uses it, I get a similar statement: "error C2143: syntax error: missing"; before "use" in my main.cpp file.
I am running Visual Studio 2010, and I even tried disabling it all again and copying the code to a new project. Help would be greatly appreciated.
#include <Windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "glut.h"
#include "SceneObject.h"
#include <fstream>
#include <sstream>
#include <iostream>
#include <string>
using namespace std;
...
stringstream ss;
ss << "Camera (" << cam.pos.x << ", " << cam.pos.y << ", " << cam.pos.z << ")";
glClear(GL_DEPTH_BUFFER_BIT);
outputText(-1.0, 0.5, ss.str());
...
#ifndef SCENEOBJECT_H
#define SCENEOBJECT_H
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
struct point3D {
float x;
float y;
float z;
};
struct colour{
float r;
float g;
float b;
};
struct tri {
int a;
int b;
int c;
};
class SceneObject {
private:
int NUM_VERTS;
int NUM_COL;
int NUM_TRI;
point3D * vertices;
colour * colours;
tri * indices;
void drawTriangle(int a, int b, int c);
public:
SceneObject(const string fName) {
read_file(fName);
}
void drawShape()
{
}
int read_file (const string fileName)
{
ifstream inFile;
inFile.open(fileName);
if (!inFile.good())
{
cerr << "Can't open file" << endl;
NUM_TRI = 0;
return 1;
}
inFile >> NUM_VERTS;
vertices = new point3D[NUM_VERTS];
for (int i=0; i < NUM_VERTS; i++)
{
inFile >> vertices[i].x;
inFile >> vertices[i].y;
inFile >> vertices[i].z;
}
inFile >> NUM_COL;
colours = new colour[NUM_COL];
for (int i=0; i < NUM_COL; i++)
{
inFile >> colours[i].r;
inFile >> colours[i].g;
inFile >> colours[i].b;
}
inFile >> NUM_TRI;
indices = new tri[NUM_TRI];
for (int i=0; i < NUM_TRI; i++)
{
inFile >> indices[i].a;
inFile >> indices[i].b;
inFile >> indices[i].c;
}
inFile.close();
return 0;
}
}
#endif
I have not changed the code and, as far as I know, there are half-columns where they should be. Even my friend, who had been programming for 5 years, could not solve this. If necessary, I will include any other specific code. And when I said new for C ++ and OpenGL, I really did a lot of VERY new. This is even my first post. I will get there in the end.
source
share