Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualwabbz111

Posted 14 October 2012 - 03:52 AM

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 verticesstruct THeader{int vertlen; //amount of vertices you want to saveTHeader();};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);////*///Loadint 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 headerfread(&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]

#1wabbz111

Posted 14 October 2012 - 03:48 AM

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, please gie 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 verticesstruct THeader{int vertlen; //amount of vertices you want to saveTHeader();};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);////*///Loadint 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 headerfread(&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);}//*///*/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]

PARTNERS