• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
wabbz111

OpenGL
Save openGL objects to file

23 posts in this topic

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
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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.
0

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.
0

Share this post


Link to post
Share on other sites
[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 ___
0

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites
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 ___
-4

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites
Why do you persistently refuse to tell the actual error reported? Don't omit important information.
2

Share this post


Link to post
Share on other sites
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 ___
-5

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites
[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.
0

Share this post


Link to post
Share on other sites
[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.
0

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites
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
2

Share this post


Link to post
Share on other sites
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 ___
-5

Share this post


Link to post
Share on other sites
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.
1

Share this post


Link to post
Share on other sites
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?
0

Share this post


Link to post
Share on other sites
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?
-4

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites
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.
-4

Share this post


Link to post
Share on other sites
This type of behaviour will not be tolerated on these forums - the relevant parties have been warned. If they have further concerns, please PM myself or another moderator.

Please keep all further discussion in this thread on topic.
1

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  
Followers 0

  • Similar Content

    • By Solid_Spy
      Hello, I have been working on SH Irradiance map rendering, and I have been using a GLSL pixel shader to render SH irradiance to 2D irradiance maps for my static objects. I already have it working with 9 3D textures so far for the first 9 SH functions.
      In my GLSL shader, I have to send in 9 SH Coefficient 3D Texures that use RGBA8 as a pixel format. RGB being used for the coefficients for red, green, and blue, and the A for checking if the voxel is in use (for the 3D texture solidification shader to prevent bleeding).
      My problem is, I want to knock this number of textures down to something like 4 or 5. Getting even lower would be a godsend. This is because I eventually plan on adding more SH Coefficient 3D Textures for other parts of the game map (such as inside rooms, as opposed to the outside), to circumvent irradiance probe bleeding between rooms separated by walls. I don't want to reach the 32 texture limit too soon. Also, I figure that it would be a LOT faster.
      Is there a way I could, say, store 2 sets of SH Coefficients for 2 SH functions inside a texture with RGBA16 pixels? If so, how would I extract them from inside GLSL? Let me know if you have any suggestions ^^.
    • By KarimIO
      EDIT: I thought this was restricted to Attribute-Created GL contexts, but it isn't, so I rewrote the post.
      Hey guys, whenever I call SwapBuffers(hDC), I get a crash, and I get a "Too many posts were made to a semaphore." from Windows as I call SwapBuffers. What could be the cause of this?
      Update: No crash occurs if I don't draw, just clear and swap.
      static PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be { sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor 1, // Version Number PFD_DRAW_TO_WINDOW | // Format Must Support Window PFD_SUPPORT_OPENGL | // Format Must Support OpenGL PFD_DOUBLEBUFFER, // Must Support Double Buffering PFD_TYPE_RGBA, // Request An RGBA Format 32, // Select Our Color Depth 0, 0, 0, 0, 0, 0, // Color Bits Ignored 0, // No Alpha Buffer 0, // Shift Bit Ignored 0, // No Accumulation Buffer 0, 0, 0, 0, // Accumulation Bits Ignored 24, // 24Bit Z-Buffer (Depth Buffer) 0, // No Stencil Buffer 0, // No Auxiliary Buffer PFD_MAIN_PLANE, // Main Drawing Layer 0, // Reserved 0, 0, 0 // Layer Masks Ignored }; if (!(hDC = GetDC(windowHandle))) return false; unsigned int PixelFormat; if (!(PixelFormat = ChoosePixelFormat(hDC, &pfd))) return false; if (!SetPixelFormat(hDC, PixelFormat, &pfd)) return false; hRC = wglCreateContext(hDC); if (!hRC) { std::cout << "wglCreateContext Failed!\n"; return false; } if (wglMakeCurrent(hDC, hRC) == NULL) { std::cout << "Make Context Current Second Failed!\n"; return false; } ... // OGL Buffer Initialization glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glBindVertexArray(vao); glUseProgram(myprogram); glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_SHORT, (void *)indexStart); SwapBuffers(GetDC(window_handle));  
    • By Tchom
      Hey devs!
       
      I've been working on a OpenGL ES 2.0 android engine and I have begun implementing some simple (point) lighting. I had something fairly simple working, so I tried to get fancy and added color-tinting light. And it works great... with only one or two lights. Any more than that, the application drops about 15 frames per light added (my ideal is at least 4 or 5). I know implementing lighting is expensive, I just didn't think it was that expensive. I'm fairly new to the world of OpenGL and GLSL, so there is a good chance I've written some crappy shader code. If anyone had any feedback or tips on how I can optimize this code, please let me know.
       
      Vertex Shader
      uniform mat4 u_MVPMatrix; uniform mat4 u_MVMatrix; attribute vec4 a_Position; attribute vec3 a_Normal; attribute vec2 a_TexCoordinate; varying vec3 v_Position; varying vec3 v_Normal; varying vec2 v_TexCoordinate; void main() { v_Position = vec3(u_MVMatrix * a_Position); v_TexCoordinate = a_TexCoordinate; v_Normal = vec3(u_MVMatrix * vec4(a_Normal, 0.0)); gl_Position = u_MVPMatrix * a_Position; } Fragment Shader
      precision mediump float; uniform vec4 u_LightPos["+numLights+"]; uniform vec4 u_LightColours["+numLights+"]; uniform float u_LightPower["+numLights+"]; uniform sampler2D u_Texture; varying vec3 v_Position; varying vec3 v_Normal; varying vec2 v_TexCoordinate; void main() { gl_FragColor = (texture2D(u_Texture, v_TexCoordinate)); float diffuse = 0.0; vec4 colourSum = vec4(1.0); for (int i = 0; i < "+numLights+"; i++) { vec3 toPointLight = vec3(u_LightPos[i]); float distance = length(toPointLight - v_Position); vec3 lightVector = normalize(toPointLight - v_Position); float diffuseDiff = 0.0; // The diffuse difference contributed from current light diffuseDiff = max(dot(v_Normal, lightVector), 0.0); diffuseDiff = diffuseDiff * (1.0 / (1.0 + ((1.0-u_LightPower[i])* distance * distance))); //Determine attenuatio diffuse += diffuseDiff; gl_FragColor.rgb *= vec3(1.0) / ((vec3(1.0) + ((vec3(1.0) - vec3(u_LightColours[i]))*diffuseDiff))); //The expensive part } diffuse += 0.1; //Add ambient light gl_FragColor.rgb *= diffuse; } Am I making any rookie mistakes? Or am I just being unrealistic about what I can do? Thanks in advance
    • By yahiko00
      Hi,
      Not sure to post at the right place, if not, please forgive me...
      For a game project I am working on, I would like to implement a 2D starfield as a background.
      I do not want to deal with static tiles, since I plan to slowly animate the starfield. So, I am trying to figure out how to generate a random starfield for the entire map.
      I feel that using a uniform distribution for the stars will not do the trick. Instead I would like something similar to the screenshot below, taken from the game Star Wars: Empire At War (all credits to Lucasfilm, Disney, and so on...).

      Is there someone who could have an idea of a distribution which could result in such a starfield?
      Any insight would be appreciated
    • By afraidofdark
      I have just noticed that, in quake 3 and half - life, dynamic models are effected from light map. For example in dark areas, gun that player holds seems darker. How did they achieve this effect ? I can use image based lighting techniques however (Like placing an environment probe and using it for reflections and ambient lighting), this tech wasn't used in games back then, so there must be a simpler method to do this.
      Here is a link that shows how modern engines does it. Indirect Lighting Cache It would be nice if you know a paper that explains this technique. Can I apply this to quake 3' s light map generator and bsp format ?
  • Popular Now