Sign in to follow this  
wabbz111

OpenGL Save openGL objects to file

Recommended Posts

wabbz111    162
Hi guys,
I am making an L-sytem tree application. I require a way to save the generated models into a text file(.obj seems the best as it saves the vertices). Check [url="http://homepages.cs.ncl.ac.uk/jonathan.hook/lsystems.html"]this[/url] site for the L-system framework
I know how read and write to a text with plain C++ but the withOpenGL it is not straight forward.
Can someone please provide me with any help on this matter.?
Preferablly an example like saving the openGL cube or teapot veryices into a text file. Thanks

Share this post


Link to post
Share on other sites
GeneralQuery    1263
There is no such concept as an OpenGL cube or teapot, you supply the geometry to the API and it is your responsibility to serialize/deserialize geometry and other assets yourself.

What specifically are you trying to do? Save a mesh you've generated yourself to disk? If so, you will need to write the geometry in the file format of your choice or use a library like the dubiously titled AssImp.

Share this post


Link to post
Share on other sites
wabbz111    162
Thanks GeneralQuery yes saving the mesh is what i am trying to do.
I will check out AssImp but if you know a way of writing the geometry
in .OBJ format i will really appreciate it.

Share this post


Link to post
Share on other sites
GeneralQuery    1263
AssImp, AFAIK, can export meshes to a number of formats, including OBJ. You could implement your own OBJ exporter as it's simple enough but IMO you may as well use an existing solution unless you wish to do this as an academic exercise. It's a fairly boring process to DIY and you'll get far more flexibility and less headaches from using something like AssImp. You can reverse engineer the OBJ format easily enough or check out one of the many tutorials on the topic, or even lift the code from AssImp if you so desire.

Share this post


Link to post
Share on other sites
Why do you need to save the generated vertices?

I mean, it's a well defined, recursion driven system - You can simply save the proper function, and then run the generation algorithm whenever the object is actually needed.

Share this post


Link to post
Share on other sites
WiredCat    1452
[b][color=#ff0000]lol i didnt read about writing it as text file well it is more complicated than this (loading)[/color][/b]

well if you want to save vertices only just do sth like this
[CODE]
struct THeader{
int vertlen; //amount of vertices you want to save
};

struct t3dpoint {
float x;
float y;
float z;
};
FILE* f = fopen(filename,"wb+");

fwrite(&header,sizeof(THeader),1,f);

now you can save them
//through all vertices in array
for (j=0; j < header.vertlen ; j++) fwrite(&verts[j],sizeof(verts[j]),1,f); //or sizeof t3dpoint (whatever)
fclose(f);
[/CODE]



and you want to load them


[CODE]


int length;
int j;
FILE* f = fopen(filename,"rb");

memset(&header,0,sizeof(THeader)); //do this if header consist more than one var if not ther is no need even to make a struct from header
fread(&header,sizeof(THeader),1,f);

int j;

set the length of verts - array in excample it can be simple pointer (t3dpoint * verts;)
verts = new t3dpoint[header.vertlen];
for (j=0; j < header.vertlen ; j++) {
t3dpoint imo;
fread(&imo,sizeof(imo),1,f);
verts[j] = imo; //something like this i use static arrays so i just assign it like thus if this does not work you will need to write (*verts[i]) = imo; but have no idea if it will work anyway :P
}

fclose(f);
}[/CODE]


Congrats! you have your own file type Edited by ___

Share this post


Link to post
Share on other sites
wabbz111    162
Thanks for the replies people.
This question is addressed to ____ ,
I have tried using your sample code to save the vertices of an opengl cube to file but
i keep getting errors can you please provide a way foward. Thanks

Share this post


Link to post
Share on other sites
WiredCat    1452
pls tell me what sort of errors, where compiler sees the error? or the progarm breaks when loading saving, pls also give code what you use, cheers
[b]and almost forgot add #include "iostream.h"[/b] Edited by ___

Share this post


Link to post
Share on other sites
wabbz111    162
Hi _____,
Iam using the first part of your code the error is on this line
fwrite(&header,sizeof(THeader),1,f);


My full code is below, iam just trying to save the cube vertices into memory
please give me any ideas you might have. Thanks
[source lang="cpp"]

#include <GL/freeglut.h>
#include <iostream>
#include <stdio.h>
bool fullscreen = false;
bool mouseDown = false;

float xrot = 0.0f;
float yrot = 0.0f;

float xdiff = 0.0f;
float ydiff = 0.0f;

void drawBox()
{
glColor3f(0.0f, 0.0f, 1.0f);
glutSolidCube(2);
}

bool init()
{
glClearColor(0.93f, 0.93f, 0.93f, 0.0f);

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glClearDepth(1.0f);

return true;
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

gluLookAt(
0.0f, 0.0f, 3.0f,
0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f);

glRotatef(xrot, 1.0f, 0.0f, 0.0f);
glRotatef(yrot, 0.0f, 1.0f, 0.0f);


drawBox();

glFlush();
glutSwapBuffers();
}

void resize(int w, int h)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glViewport(0, 0, w, h);

gluPerspective(45.0f, 1.0f * w / h, 1.0f, 100.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void idle()
{
if (!mouseDown)
{
xrot += 0.3f;
yrot += 0.4f;
}

glutPostRedisplay();
}

void keyboard(unsigned char key, int x, int y)
{
switch(key)
{
case 27 :
exit(1); break;
}
}




//*
///save vertices
struct THeader{
int vertlen; //amount of vertices you want to save
THeader();
};

struct t3dpoint {
float x;
float y;
float z;
};
FILE* f = fopen("vertices.txt","wb+");

fwrite(&header,sizeof(THeader),1,f);

//now you can save them
//through all vertices in array
for (j=0; j < header.vertlen ; j++) fwrite(&verts[j],sizeof(verts[j]),1,f); //or sizeof t3dpoint (whatever)
fclose(f);
///

/*///Load
int length;
int j;
FILE* f = fopen(filename,"rb");

memset(&header,0,sizeof(THeader)); //do this if header consist more than one var if not ther is no need even to make a struct from header
fread(&header,sizeof(THeader),1,f);

int j;

//set the length of verts - array in excample it can be simple pointer (t3dpoint * verts;)
verts = new t3dpoint[header.vertlen];
for (j=0; j < header.vertlen ; j++) {
t3dpoint imo;
fread(&imo,sizeof(imo),1,f);
verts[j] = imo; //something like this i use static arrays so i just assign it like thus if this does not work you will need to write (*verts[i]) = imo; but have no idea if it will work anyway [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img]
}

fclose(f);
}
//*/
//*/
int main(int argc, char *argv[])
{
glutInit(&argc, argv);

glutInitWindowPosition(50, 50);
glutInitWindowSize(500, 500);

glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);

glutCreateWindow("13 - Solid Shapes");

glutDisplayFunc(display);
glutKeyboardFunc(keyboard);

glutReshapeFunc(resize);
glutIdleFunc(idle);

if (!init())
return 1;

glutMainLoop();

return 0;
}

[/source] Edited by wabbz111

Share this post


Link to post
Share on other sites
WiredCat    1452
first thing do not use constructor in structure you want to save(ermove it) sec problem is you are not saving any vertices at all you haven't defined them glutSolidCube(2); will not define the vertices you want to save , last thing you are not saving verts in a function!!!! dude create a function that save verts, place structures in a header so it should be like this:

void saveverts()
{

FILE* f = fopen("vertices.txt","wb+");

fwrite(&header,sizeof(THeader),1,f);
rest of code

}
i am not a fairy please write an error you get
and you have
#include
#include
#include incldue what????


maybe you should start learn how to write programs, as far i can see you have no idea what you are doing Edited by ___

Share this post


Link to post
Share on other sites
wabbz111    162
Sorry about not reporting the errors.
About the missing #includes that is a problem when pasting
but the three libraries iam using are:
#include <GL/freeglut.h>
#include <iostream>
#include <stdio>
Here is the full error list i will try implement your suggestions. Cheers

[source lang="cpp"]shapes.cpp:168: error: expected constructor, destructor, or type conversion before '*' token

shapes.cpp:168: error: expected `,' or `;' before '*' token
shapes.cpp:170: error: expected constructor, destructor, or type conversion before '(' token
shapes.cpp:170: error: expected `,' or `;' before '(' token
shapes.cpp:174: error: expected unqualified-id before "for"
shapes.cpp:174: error: expected `,' or `;' before "for"
shapes.cpp:174: error: expected constructor, destructor, or type conversion before '<' token
shapes.cpp:174: error: expected `,' or `;' before '<' token
shapes.cpp:174: error: expected constructor, destructor, or type conversion before '++' token
shapes.cpp:174: error: expected `,' or `;' before '++' token
shapes.cpp:175: error: expected constructor, destructor, or type conversion before '(' token
shapes.cpp:175: error: expected `,' or `;' before '(' token

make.exe: *** [shapes.o] Error 1

Execution terminated[/source]

Here is the source code cube with vertices defined(without the changes reccomended)

[source lang="cpp"]

#include <GL/freeglut.h>
#include <iostream>
#include <stdio>

bool fullscreen = false;
bool mouseDown = false;

float xrot = 0.0f;
float yrot = 0.0f;

float xdiff = 0.0f;
float ydiff = 0.0f;

void drawBox()
{
glBegin(GL_QUADS);

glColor3f(1.0f, 0.0f, 0.0f);
// FRONT
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f( 0.5f, -0.5f, 0.5f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
// BACK
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f( 0.5f, 0.5f, -0.5f);
glVertex3f( 0.5f, -0.5f, -0.5f);

glColor3f(0.0f, 1.0f, 0.0f);
// LEFT
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f(-0.5f, -0.5f, -0.5f);
// RIGHT
glVertex3f( 0.5f, -0.5f, -0.5f);
glVertex3f( 0.5f, 0.5f, -0.5f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f( 0.5f, -0.5f, 0.5f);

glColor3f(0.0f, 0.0f, 1.0f);
// TOP
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f( 0.5f, 0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
// BOTTOM
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f( 0.5f, -0.5f, -0.5f);
glVertex3f( 0.5f, -0.5f, 0.5f);
glEnd();
}

bool init()
{
glClearColor(0.93f, 0.93f, 0.93f, 0.0f);

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glClearDepth(1.0f);

return true;
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

gluLookAt(
0.0f, 0.0f, 3.0f,
0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f);

glRotatef(xrot, 1.0f, 0.0f, 0.0f);
glRotatef(yrot, 0.0f, 1.0f, 0.0f);

drawBox();

glFlush();
glutSwapBuffers();
}

void resize(int w, int h)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glViewport(0, 0, w, h);

gluPerspective(45.0f, 1.0f * w / h, 1.0f, 100.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void idle()
{
if (!mouseDown)
{
xrot += 0.3f;
yrot += 0.4f;
}

glutPostRedisplay();
}

void keyboard(unsigned char key, int x, int y)
{
switch(key)
{
case 27 :
exit(1); break;
}
}

void specialKeyboard(int key, int x, int y)
{
if (key == GLUT_KEY_F1)
{
fullscreen = !fullscreen;

if (fullscreen)
glutFullScreen();
else
{
glutReshapeWindow(500, 500);
glutPositionWindow(50, 50);
}
}
}

void mouse(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
mouseDown = true;

xdiff = x - yrot;
ydiff = -y + xrot;
}
else
mouseDown = false;
}

void mouseMotion(int x, int y)
{
if (mouseDown)
{
yrot = x - xdiff;
xrot = y + ydiff;

glutPostRedisplay();
}
}

//*
///save vertices
struct THeader{
int vertlen; //amount of vertices you want to save
};

struct t3dpoint {
float x;
float y;
float z;
};
FILE* f = fopen(filename,"wb+");

fwrite(&header,sizeof(THeader),1,f);

//now you can save them
//through all vertices in array
for (j=0; j < header.vertlen ; j++) fwrite(&verts[j],sizeof(verts[j]),1,f); //or sizeof t3dpoint (whatever)
fclose(f);
//*/

int main(int argc, char *argv[])
{
glutInit(&argc, argv);

glutInitWindowPosition(50, 50);
glutInitWindowSize(500, 500);

glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);

glutCreateWindow("13 - Solid Shapes");

glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutSpecialFunc(specialKeyboard);
glutMouseFunc(mouse);
glutMotionFunc(mouseMotion);
glutReshapeFunc(resize);
glutIdleFunc(idle);

if (!init())
return 1;

glutMainLoop();

return 0;
}

[/source] Edited by wabbz111

Share this post


Link to post
Share on other sites
BitMaster    8651
[quote name='___' timestamp='1350127144' post='4989734']
pls tell me what sort of errors, where compiler sees the error? or the progarm breaks when loading saving, pls also give code what you use, cheers
[b]and almost forgot add #include "iostream.h"[/b]
[/quote]
'iostream.h' is an extremely old and deprecated header which might not even be there depending on the compiler. You should never ever use it. The header in the C++ standard library is called 'iostream' without any .h.

Share this post


Link to post
Share on other sites
BitMaster    8651
[quote name='___' timestamp='1350254918' post='4990179']
first thing do not use constructor in structure you want to save(ermove it)
[/quote]
That is plain wrong. A constructor is fine since it does not change the memory layout. A virtual function does though. That said, the point is moot anyway because in general it is not a good idea to serialize whole structures (padding happens and will not always be the same between compilers or platforms). A better habit is to serialize the individual members.

Share this post


Link to post
Share on other sites
BitMaster    8651
wabbz111, are the error lines actually correct? I cannot make immediate sense of the error message in line 168.

That aside, why did you change your initial plan to output as a readable text format? Writing to a text file will be much easier to debug and a simple Wavefront obj file (containing only vertices and indices, maybe normals) is not that difficult to achieve (the corresponding [url="http://en.wikipedia.org/wiki/Wavefront_OBJ"]Wikipedia entry[/url] contains all relevant information for that task).
Being able to check the validity of a file using a verified 3rd party program is priceless during development. If something does not work you know your writer is at fault instead of having to develop a reader as well and then trying to figure out which is wrong when it does not work (it never works the first time).

A very simple Wavefront obj exporter would be:
[code]
#include <vector>
#include <string>
#include <fstream>

void writeObject(const std::string& fileName, const std::vector<point>& points, const std::vector<int>& indices)
{
std::ofstream os(fileName.c_str());
for (std::size_t i = 0; i < points.size(); ++i)
os << "v " << points[i].x << " " points[i].y << " " << points[i].z << "\n";
for (std::size_t i = 0; i < indices.size(); i += 3)
os << "f " << (indices[i] + 1) << " " << (indices[i + 1] + 1) << " " << (indices[i + 2] + 1) << "\n";
}
[/code]
Not tested, but should work out of the box or with minimal cleanup. The only important caveat is that Wavefront obj files use one-based indices. If you account for that, writing or reading them is pretty straight forward. Of course, if you want reading non-trivial obj files or even different file formats I would still suggest using a library like Assimp.

Edit: <fstream> is needed, not <iostream>. Sorry for the inconvenience. Edited by BitMaster

Share this post


Link to post
Share on other sites
BitMaster    8651
The first important step is verifying the writer works. Being able to do that with an external, already verified tool, will (as I already said) save a lot of headache.

Once that is done, reading the same Wavefronts as generated again is pretty trivial using iostreams (I would not implement a full loader, that is what Assimp and co is for). String splitting via streams is pretty trivial.

Third, nothing in the OPs post says he has to implement a loader as well. And if he does, here is one that can loads the files generated by the writer above:
[code]
#include <vector>
#include <string>
#include <sstream>
#include <fstream>

void readObject(const std::string& fileName, std::vector<point>& points, std::vector<int>& indices)
{
points.clear();
indices.clear();

std::string line;
std::ifstream is(fileName.c_str());
while (std::getline(is, line))
{
std::string prefix;
std::istringstream iss(line);
iss >> prefix;
if (prefix == "v")
{
point pt;
iss >> pt.x >> pt.y >> pt.z;
points.push_back(pt);
}
if (prefix == "f")
{
int idx[3];
iss >> idx[0] >> idx[1] >> idx[2];
indices.push_back(idx[0] - 1);
indices.push_back(idx[1] - 1);
indices.push_back(idx[2] - 1);
}
}
}
[/code]
It's not pretty and really does not work with more complicated Wavefronts or faulty files (production code must be able to deal with invalid files) but it gets the job done for the moment. Again, for loading I would strongly advise using a full fledged loader library since developing a full and error prone loader is a rather tedious and boring exercise.

Edit: <fstream> is needed, not <iostream>. Sorry for the inconvenience.
Edit2: istrstream was the old deprecated string stream. istringstream is what should be used. Edited by BitMaster

Share this post


Link to post
Share on other sites
WiredCat    1452
I have changed your code :


I have changed your code :

[CODE]
#include "iostream.h" //sometimes need '#include "#stdio.h" ' or stdlib ;]

struct THeader{
int vertlen; //amount of vertices you want to save
};
struct t3dpoint {
float x;
float y;
float z;
};

THeader header;
t3dpoint * verts;


bool fullscreen = false;
bool mouseDown = false;
float xrot = 0.0f;
float yrot = 0.0f;
float xdiff = 0.0f;
float ydiff = 0.0f;
t3dpoint vertin(float x, float y, float z)
{
t3dpoint k;
k.x = x;
k.y = y;
k.z = z;
return k;
}
void CreateModelArray()
{
verts = new t3dpoint[24];

header.vertlen = 24;
verts[0] = vertin(-0.5f, -0.5f, 0.5f);
verts[1] = vertin( 0.5f, -0.5f, 0.5f);
verts[2] = vertin( 0.5f, 0.5f, 0.5f);
verts[3] = vertin(-0.5f, 0.5f, 0.5f);
// BACK
verts[4] = vertin(-0.5f, -0.5f, -0.5f);
verts[5] = vertin(-0.5f, 0.5f, -0.5f);
verts[6] = vertin( 0.5f, 0.5f, -0.5f);
verts[7] = vertin( 0.5f, -0.5f, -0.5f);

// LEFT
verts[8] = vertin(-0.5f, -0.5f, 0.5f);
verts[9] = vertin(-0.5f, 0.5f, 0.5f);
verts[10] = vertin(-0.5f, 0.5f, -0.5f);
verts[11] = vertin(-0.5f, -0.5f, -0.5f);
// RIGHT
verts[12] = vertin( 0.5f, -0.5f, -0.5f);
verts[13] = vertin( 0.5f, 0.5f, -0.5f);
verts[14] = vertin( 0.5f, 0.5f, 0.5f);
verts[15] = vertin( 0.5f, -0.5f, 0.5f);

// TOP
verts[16] = vertin(-0.5f, 0.5f, 0.5f);
verts[17] = vertin( 0.5f, 0.5f, 0.5f);
verts[18] = vertin( 0.5f, 0.5f, -0.5f);
verts[19] = vertin(-0.5f, 0.5f, -0.5f);
// BOTTOM
verts[20] = vertin(-0.5f, -0.5f, 0.5f);
verts[21] = vertin(-0.5f, -0.5f, -0.5f);
verts[22] = vertin( 0.5f, -0.5f, -0.5f);
verts[23] = vertin( 0.5f, -0.5f, 0.5f);
}
void drawBox()
{
int i;
glColor3f(1.0f, 0.0f, 0.0f);
glBegin(GL_QUADS);
for (i=0; i<24;i++)
glVertex3f(verts[i].x,verts[i].y,verts[i].z);


glEnd();
}
bool init()
{
glClearColor(0.93f, 0.93f, 0.93f, 0.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glClearDepth(1.0f);
return true;
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(
0.0f, 0.0f, 3.0f,
0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f);
glRotatef(xrot, 1.0f, 0.0f, 0.0f);
glRotatef(yrot, 0.0f, 1.0f, 0.0f);
drawBox();
glFlush();
glutSwapBuffers();
}
void resize(int w, int h)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, w, h);
gluPerspective(45.0f, 1.0f * w / h, 1.0f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void idle()
{
if (!mouseDown)
{
xrot += 0.3f;
yrot += 0.4f;
}
glutPostRedisplay();
}
void keyboard(unsigned char key, int x, int y)
{
switch(key)
{
case 27 :
exit(1); break;
}
}
void specialKeyboard(int key, int x, int y)
{
if (key == GLUT_KEY_F1)
{
fullscreen = !fullscreen;
if (fullscreen)
glutFullScreen();
else
{
glutReshapeWindow(500, 500);
glutPositionWindow(50, 50);
}
}
}
void mouse(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
mouseDown = true;
xdiff = x - yrot;
ydiff = -y + xrot;
}
else
mouseDown = false;
}
void mouseMotion(int x, int y)
{
if (mouseDown)
{
yrot = x - xdiff;
xrot = y + ydiff;
glutPostRedisplay();
}
}

void savemodel(char *filename)
{
FILE* f = fopen(filename,"wb+");
fwrite(&header,sizeof(THeader),1,f);

for (j=0; j < header.vertlen ; j++) fwrite(&verts[j],sizeof(verts[j]),1,f);
fclose(f);
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowPosition(50, 50);
glutInitWindowSize(500, 500);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);

glutCreateWindow("13 - Solid Shapes");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutSpecialFunc(specialKeyboard);
glutMouseFunc(mouse);
glutMotionFunc(mouseMotion);
glutReshapeFunc(resize);
glutIdleFunc(idle);
CreateModelArray();
if (!init())
return 1;
glutMainLoop();
return 0;
}[/CODE] Edited by ___

Share this post


Link to post
Share on other sites
BitMaster    8651
Again, 'iostream.h' is an old and deprecated header. The header you are looking for is 'iostream'. And if you need the C header 'stdio.h' then you should include 'cstdio' (note the missing .h and leading c). Same goes for 'stdlib.h'. That is a C header and when using it in C++ you should include 'cstdlib' instead.

Share this post


Link to post
Share on other sites
BitMaster    8651
Okay, let me sum this up. First, you present the OP with a solution that does not do what he wants (he wants to write text files, you offer him binary files). Then you make several mistakes (like using headers that don't exist) and when corrected (repeatedly) you go on an indiscriminate crusade of downvoting? Was anything I said actually factually incorrect (if so, I'm happy to be corrected) or are you just petty?

Share this post


Link to post
Share on other sites
WiredCat    1452
tell me where the mistakes are and why did you and your stupid friends downvoted me. headers that do not exist yea right, read
[quote]

hanks for the replies people.
This question is addressed to ____ ,
I have tried using your sample code to save the vertices of an opengl cube to file but
i keep getting errors can you please provide a way foward. Thanks[/quote]


and what is it?

Share this post


Link to post
Share on other sites
BitMaster    8651
I have clearly commented every instance where I downvoted you in my posts including exactly which information is wrong.

On a sidenote: I did not call in any 'friends' to downvote you or upvote me again. I downvoted you exactly thrice, each time I added a post where I explained my reasoning as well what exactly I believe to be wrong.

For the record: 'iostream.h' does not exist in my default configuration of MSVC 2008. It was an old header way back from VC6, from before C++ was standardized. No compiler is guaranteed to ship with one (I believe MSVC 2005 still had it) but there is absolutely no point in using it nowadays. In fact, it's extremely counterproductive since most compilers won't even have it and it is not even standard compliant. Edited by BitMaster

Share this post


Link to post
Share on other sites
WiredCat    1452
and this is your holly reason to give me negative score because 'i don't have it', POOR CHILD!!!!!!!
so i have changed his code, because i wanted to help him and then you downvoted it because you don't have that header mr i know everything, please stfu and leave.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By Zaphyk
      I am developing my engine using the OpenGL 3.3 compatibility profile. It runs as expected on my NVIDIA card and on my Intel Card however when I tried it on an AMD setup it ran 3 times worse than on the other setups. Could this be a AMD driver thing or is this probably a problem with my OGL code? Could a different code standard create such bad performance?
    • By Kjell Andersson
      I'm trying to get some legacy OpenGL code to run with a shader pipeline,
      The legacy code uses glVertexPointer(), glColorPointer(), glNormalPointer() and glTexCoordPointer() to supply the vertex information.
      I know that it should be using setVertexAttribPointer() etc to clearly define the layout but that is not an option right now since the legacy code can't be modified to that extent.
      I've got a version 330 vertex shader to somewhat work:
      #version 330 uniform mat4 osg_ModelViewProjectionMatrix; uniform mat4 osg_ModelViewMatrix; layout(location = 0) in vec4 Vertex; layout(location = 2) in vec4 Normal; // Velocity layout(location = 3) in vec3 TexCoord; // TODO: is this the right layout location? out VertexData { vec4 color; vec3 velocity; float size; } VertexOut; void main(void) { vec4 p0 = Vertex; vec4 p1 = Vertex + vec4(Normal.x, Normal.y, Normal.z, 0.0f); vec3 velocity = (osg_ModelViewProjectionMatrix * p1 - osg_ModelViewProjectionMatrix * p0).xyz; VertexOut.velocity = velocity; VertexOut.size = TexCoord.y; gl_Position = osg_ModelViewMatrix * Vertex; } What works is the Vertex and Normal information that the legacy C++ OpenGL code seem to provide in layout location 0 and 2. This is fine.
      What I'm not getting to work is the TexCoord information that is supplied by a glTexCoordPointer() call in C++.
      Question:
      What layout location is the old standard pipeline using for glTexCoordPointer()? Or is this undefined?
       
      Side note: I'm trying to get an OpenSceneGraph 3.4.0 particle system to use custom vertex, geometry and fragment shaders for rendering the particles.
    • By markshaw001
      Hi i am new to this forum  i wanted to ask for help from all of you i want to generate real time terrain using a 32 bit heightmap i am good at c++ and have started learning Opengl as i am very interested in making landscapes in opengl i have looked around the internet for help about this topic but i am not getting the hang of the concepts and what they are doing can some here suggests me some good resources for making terrain engine please for example like tutorials,books etc so that i can understand the whole concept of terrain generation.
       
    • By KarimIO
      Hey guys. I'm trying to get my application to work on my Nvidia GTX 970 desktop. It currently works on my Intel HD 3000 laptop, but on the desktop, every bind textures specifically from framebuffers, I get half a second of lag. This is done 4 times as I have three RGBA textures and one depth 32F buffer. I tried to use debugging software for the first time - RenderDoc only shows SwapBuffers() and no OGL calls, while Nvidia Nsight crashes upon execution, so neither are helpful. Without binding it runs regularly. This does not happen with non-framebuffer binds.
      GLFramebuffer::GLFramebuffer(FramebufferCreateInfo createInfo) { glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); textures = new GLuint[createInfo.numColorTargets]; glGenTextures(createInfo.numColorTargets, textures); GLenum *DrawBuffers = new GLenum[createInfo.numColorTargets]; for (uint32_t i = 0; i < createInfo.numColorTargets; i++) { glBindTexture(GL_TEXTURE_2D, textures[i]); GLint internalFormat; GLenum format; TranslateFormats(createInfo.colorFormats[i], format, internalFormat); // returns GL_RGBA and GL_RGBA glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, createInfo.width, createInfo.height, 0, format, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); DrawBuffers[i] = GL_COLOR_ATTACHMENT0 + i; glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, textures[i], 0); } if (createInfo.depthFormat != FORMAT_DEPTH_NONE) { GLenum depthFormat; switch (createInfo.depthFormat) { case FORMAT_DEPTH_16: depthFormat = GL_DEPTH_COMPONENT16; break; case FORMAT_DEPTH_24: depthFormat = GL_DEPTH_COMPONENT24; break; case FORMAT_DEPTH_32: depthFormat = GL_DEPTH_COMPONENT32; break; case FORMAT_DEPTH_24_STENCIL_8: depthFormat = GL_DEPTH24_STENCIL8; break; case FORMAT_DEPTH_32_STENCIL_8: depthFormat = GL_DEPTH32F_STENCIL8; break; } glGenTextures(1, &depthrenderbuffer); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); glTexImage2D(GL_TEXTURE_2D, 0, depthFormat, createInfo.width, createInfo.height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthrenderbuffer, 0); } if (createInfo.numColorTargets > 0) glDrawBuffers(createInfo.numColorTargets, DrawBuffers); else glDrawBuffer(GL_NONE); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) std::cout << "Framebuffer Incomplete\n"; glBindFramebuffer(GL_FRAMEBUFFER, 0); width = createInfo.width; height = createInfo.height; } // ... // FBO Creation FramebufferCreateInfo gbufferCI; gbufferCI.colorFormats = gbufferCFs.data(); gbufferCI.depthFormat = FORMAT_DEPTH_32; gbufferCI.numColorTargets = gbufferCFs.size(); gbufferCI.width = engine.settings.resolutionX; gbufferCI.height = engine.settings.resolutionY; gbufferCI.renderPass = nullptr; gbuffer = graphicsWrapper->CreateFramebuffer(gbufferCI); // Bind glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); // Draw here... // Bind to textures glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, textures[0]); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, textures[1]); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, textures[2]); glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); Here is an extract of my code. I can't think of anything else to include. I've really been butting my head into a wall trying to think of a reason but I can think of none and all my research yields nothing. Thanks in advance!
    • By Adrianensis
      Hi everyone, I've shared my 2D Game Engine source code. It's the result of 4 years working on it (and I still continue improving features ) and I want to share with the community. You can see some videos on youtube and some demo gifs on my twitter account.
      This Engine has been developed as End-of-Degree Project and it is coded in Javascript, WebGL and GLSL. The engine is written from scratch.
      This is not a professional engine but it's for learning purposes, so anyone can review the code an learn basis about graphics, physics or game engine architecture. Source code on this GitHub repository.
      I'm available for a good conversation about Game Engine / Graphics Programming
  • Popular Now