Jump to content
  • Advertisement
jakeplow

white dragon finger paint

Recommended Posts

im trying to save file as file.x old microsoft style .x files

this code writes but it comes out as an error

i compiled it with visual c using glut 

i need to be able to both read and write .x files such as wdf.x   <---   :)


here is the code sorry about spaghetti code 

===========================================

#ifdef WIN32
#include <windows.h>
#endif
#if defined(__APPLE__) || defined(MACOSX)
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#include <gl/glut.h>
#endif
#include <stdio.h>
#include <stdlib.h>
int xt,yt,zt =0.0f;
int xtc =1.0;
#define MAX_VERTS 900000
float angle  = 0; 
float anglf  = 0;
float anglg  = 0;
float n =0.0;
GLfloat z= -0.2f;
GLfloat hl= 0.0f;
GLfloat zm= -0.2f;
GLfloat zp= 0.2f;
GLuint  mousex, mousey, mousez = 0;
static GLfloat Scale = 0.0f;
static int i= 2;
int j= 2.0;
static int numVerts = 2;
static struct {GLfloat x, y, z;} verts[MAX_VERTS][2];
static GLboolean dragMouse = GL_FALSE;  
enum {X, Y, Z};
enum {NOLIST, PLANE}; /* display lists */
enum {VERTS};
/* load data structure from file */
enum {WRITE, END};


void reshape(int w, int h) {
  glViewport(0,0, w,h);
  glLoadIdentity();
  glOrtho(0,w, h,0, -1,1);  /* flip y-axis around */
  glMatrixMode(GL_MODELVIEW);
   
}  // not used jmcd

void glRotateAxis(void){
glTranslatef(0.0f,0.0f,0.0f);
//glScalef(Scale, Scale, Scale);
glRotatef(angle,0.0f,+1.0f,+1.0f);   //on center rotation by jmcd
glTranslatef(0.0f,0.0f,0.0f);
}

void glRotateAxisB(void){
glTranslatef(0.0f,0.0f,0.0f);
//glScalef(Scale, Scale, Scale);
glRotatef(angle,0.0f,-1.0f,-1.0f);   //on center rotation by jmcd
glTranslatef(0.0f,0.0f,0.0f);
}

void glScaleIt(void)
{
glScalef(Scale, Scale, Scale);
}

void display(void) {
  glClear(GL_COLOR_BUFFER_BIT);  /* clear frame buffer */
  //glPointSize(3.0f);
glColor3f(2.0, 7.0, 3.0); /* set current color to Pastashio Green */
glMatrixMode(GL_PROJECTION);

//glTranslatef(0.0f,0.0f,0.0f);
//glRotatef(angle,1.0f,1.0f,0.0f);   //on center rotation by jmcd
//glTranslatef(0.0f,0.0f,0.0f);
//glRotatef(anglf,0.0f,1.0f,0.0f);
//glRotatef(anglg,0.0f,0.0f,1.0f);

    //glRotatef(10-.01,0.0f, 1.0f, 0.0f);

    glBegin(GL_POINTS);    //glBegin(GL_LINES);     GL_POINTS
    if (numVerts > 1) {
    int i;
   for (i = 0; i < numVerts; i++) 

glVertex3d(verts[0].x, verts[0].y, verts[0].z);

    if(dragMouse)
    //    numVerts++;
    i++;
glVertex3f((GLfloat) verts[1].x=mousex, (GLfloat) verts[1].y=mousey, (GLfloat) verts[1].z=mousez);
//glVertex3d(verts[1].x, verts[1].y, verts[1].z);
    //if(dragMouse == GL_TRUE)


    glEnd();
  }


  glutPostRedisplay();
  glFlush();  /* make sure all GL commands are executed */
}

void writer(char *fname)
{
    FILE *fp;
    GLfloat x, y, z ;
     
   int state = WRITE;
    
    int jtrig = 0.0;
    int i= 2.0;
    
    fp = fopen(fname, "wb");
    if (!fp) {
        printf("can't open file %s\n", fname);
    
    }

   // glNewList(PLANE, GL_COMPILE);
    state = WRITE;
    while(!feof(fp))
    {
    switch(state)
    
    {

    case WRITE:
 

        if (n == 0.0)
    x =    verts[0].x;
    y =    verts[0].y;
    z =    verts[0].z;
     fprintf(fp, " %f %f %f", verts[0].x, verts[0].y, verts[0].z);
      printf ("xyz : %f.\n",x,y,z);
      printf ("numverts : %f.\n",numVerts);
      //printf(fp, " %f %f %f", verts[j][0].x, verts[j][0].y, verts[j][0].z); 
     fprintf (fp, "%f \r\n",0);
     // j++;
      if(i == numVerts) 
          state = END;
          i++;
          n= 1.0;
      break;

          if (n == 1.0)
    x =    verts[1].x;
    y =    verts[1].y;
    z =    verts[1].z;
     fprintf(fp, " %f %f %f", verts[1].x, verts[1].y, verts[1].z);
      printf ("xyz : %f.\n",x,y,z);
      printf ("numverts : %f.\n",numVerts);
      //printf(fp, " %f %f %f", verts[j][0].x, verts[j][0].y, verts[j][0].z); 
     fprintf (fp, "%f \r\n",0);
     // j++;
      if(i == numVerts) 
          state = END;
          i++;
           n= 0.0;
      break;
//fclose(fp);

       if(i < numVerts)
state = WRITE;
       if (x == 0.0)
        fclose(fp);
        break;
    
          case END:
       fclose(fp);    
       state = NULL;
 state = END;
        break;

    }

    
    }
}


void loader(char *fname)
{
    FILE *fp;
    GLfloat x, y, z;
    int state = END;
    int read;
    n = 0;
    numVerts = 2.0; 
    i = 2.0;
    fp = fopen(fname, "r");
    if (!fp) {
        printf("can't open file %s\n", fname);
    exit(1);
    }

   // glNewList(PLANE, GL_COMPILE);
    state = VERTS;
    while(!feof(fp))
    {
    switch(state)
    {
    case END:
       // read = fscanf(fp, "");
      //  if(read < 0) /* hit eof */
    //    break;
        state = VERTS;
      //  glBegin(GL_LINE_STRIP);
        break;
    case VERTS:
        if( n = 0.0)
       fscanf(fp, " %f %f %f ", verts[0].x, verts[0].y, verts[0].z);
    //    fscanf(fp, " %f %f %f", &x, &y, &z);
             printf("xyz : %f./n",verts[0].x,verts[0].y,verts[0].z);  //////////////////////////////////////    printf("xyz : %f./n",x,y,z); /////
      verts[0].x = x;
      verts[0].y = y;
      verts[0].z = z;     // watch 148
      n = 1.0;
          i++;
         // numVerts = i;
       
          if( n = 1.0)
        fscanf(fp, " %f %f %f ", verts[1].x, verts[1].y, verts[1].z);
             printf("xyz : %f./n",verts[0].x,verts[0].y,verts[0].z);  //////////////////////////////////////    printf("xyz : %f./n",x,y,z); /////
      verts[1].x = x;
      verts[1].y = y;
      verts[1].z = z;     // watch 148
       n = 0.0;
          i++;
    //      numVerts = i;     @@@@@@@@@@@@@@@@@@@@@JMCD NOW!!@@@@@@@@@@@@@@


          if(x = 0.0);
         state = END;
        if (x !=0.0)
            
         state = VERTS;
      
        {
    //    fscanf(fp, "");
        //glEnd();
    //    state = END;
        }
        break;
    }
    }
  //  glEndList();
    fclose(fp);
}


void keyboard(unsigned char key, int x, int y) {

   switch (key){
       

       case 'd':
           hl=zm;
           z= hl;
         glutPostRedisplay(); 
       break;


       case 'f':
           hl=zp;
           z= hl;
         glutPostRedisplay(); 
           break;

          case 'l':
     loader("./data/wdf.x");
     glutPostRedisplay(); 
     // glFlush();
          break;

        case 'w':
     writer("./data/wdf.x");
     glutPostRedisplay(); 
     // glFlush();
          break;

       case 'u':
    numVerts--;
    i--;
    printf("xyz :  %d./n", x,y,z);
    glutPostRedisplay(); 
          break;

       case 'c':
           hl=0.0f;
           z= hl;
         glutPostRedisplay(); 
       break;
           break;


      case 's':
    numVerts=2;
    i=2;
    glutPostRedisplay(); 
          break;

           case 'r':
    numVerts++;
    i++;
    printf("xyz:  %d./n", x,y,z);
    glutPostRedisplay(); 
          break;

           case 'p':
               Scale = 0.4f;
           glScaleIt();
               break;

           case 'o':
               Scale += 0.4f;
           glScaleIt();
               break;


           case 'a':
           angle += .001f;
     printf ("angle : %f.\n", angle);
     glRotateAxisB();   
               break;

           case 'z':
     angle += .001f;
     printf ("angle : %f.\n", angle);
    glRotateAxis();   //this whole thing is right, x below also all correct
//    glutPostRedisplay();
          break;

    case 'x':
     angle -= .001f;
  glRotateAxis();

    //glutPostRedisplay();
          break;


    case 'k':
     angle -= .1;
    glRotatef(angle,1.0,0.0,0.0);
    glutPostRedisplay();
          break;

    case 'y':
     angle += .1;
    glRotatef(angle,0.0,1.0,0.0);
    glutPostRedisplay();
          break;

    case 'g':
     angle -= .1;
    glRotatef(angle,0.0,-1.0,0.0);
    glutPostRedisplay();
          break;

    //  case 'n':
    //      numVerts--;
    //glutPostRedisplay();   /* request a redisplay */
    //      break;

     /* case 'q':
      case 'Q':
       exit(0);
     break;*/
  }
}


void mouse(int button, int state, int x, int y) {
  if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN )
    if (numVerts < MAX_VERTS) {
        dragMouse = GL_TRUE;
//    printf ("Mouse in play routine : %d,%d,%d.\n", x,y,z);   //jmcd take out later !!!
      verts[0].x = x;
      verts[0].y = y;
      verts[0].z = hl;        // watch 148
      printf ("Index I: %d.\n", i);
      printf ("dragMouse : %d.\n", dragMouse);
      printf ("numVerts : %d.\n", numVerts);    //jmcd jmk 1
      printf ("hl : %f.\n", hl);
      printf ("z : %f.\n", z);

          if (xtc = 1.0)
    xt =    verts[0].x;
    yt =    verts[0].y;
    zt =    verts[0].z;
    // fwrite(fp, " %f %f %f",xt,yt,zt);
printf("xt :  %i./n ", xt);
printf("yt :  %i./n ", yt);
printf("zt :  %i./n ", zt);
xtc++;

      numVerts++;
      i++;
      glutPostRedisplay();   /* request a redisplay */
    }
}

void mouseMotion(int x, int y) {
  if (GLUT_UP == TRUE) {
      dragMouse = GL_TRUE;
      if(dragMouse) {                    //dragmouse achieved at 11:40 AM //D //8:32 AM
                 mousex = x;
             mousey = y;
        mousez = z;
    //    glMatrixMode(GL_MODELVIEW);
        glutPostRedisplay();

      }
      printf ("hl : %f.\n", hl);
         //glVertex3f((GLfloat) verts[0].x, (GLfloat) verts[0].y, (GLfloat) verts[0].z);
         //i++;
  }
   // glutPostRedisplay();   /* request a redisplay */
 
}

#define ESC 27

//void keyboard(unsigned char key, int x, int y) {if (key == ESC) exit(0);}

int main(int argc, char *argv[]) {
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
  glutInitWindowSize(500,500);
  glutInitWindowPosition(10,10);
  glutCreateWindow("Polyline Editor");
  glutDisplayFunc(display);
  glutReshapeFunc(reshape);
  glutMouseFunc(mouse);
  glutPassiveMotionFunc(mouseMotion);
  glutKeyboardFunc(keyboard);
  glClearColor(0.0, 0.0, 0.0, 1.0);
  glutMainLoop();
  return 0;
}
 

 

thank you in advance  :)   

 

sincerly JakePlow

polyed3.c

polyed3.dsp

polyed3.plg

Share this post


Link to post
Share on other sites
Advertisement

This did not belong in Game Design (game design is not about programming). It's moved to a more appropriate forum.

Share this post


Link to post
Share on other sites
Posted (edited)

Hello, I took a look at this briefly. I'm not going to say your code is bad, (whoops) :) but could use some improvement. The area I would attack first is cleanliness. You are sloppy with your bracing. Case in point inside the function named writer...

On 5/25/2019 at 6:56 AM, jakeplow said:

while(!feof(fp))
    {
    switch(state)
    
    {

    case WRITE:
 

        if (n == 0.0)
    x =    verts[0].x;
    y =    verts[0].y;
    z =    verts[0].z;

Here, the variable assignment to x may or may not happen depending the whatever n is supposed to be but y and z always get theirs. 

edit: worse yet, it will only write the first vertex.

Edited by GoliathForge

Share this post


Link to post
Share on other sites

you have not seen this code in action, there isn't anything like it anywhere ,not even close

 

after you start it up you type c for one dimention and for drawing on the next temple with respect to 0.00   

type a z x as needed all drawing done with mouse 

all code is glut and opengl compatble and was code on visual c ansi style

 

 

you can create a movable world of stars all in 3D

what i wanted to do is create a game where triangler star ships that battle as they mov in

a big figure 8 and they shoot as they go, it would take a while to get used to it but code can be added that can handle steering also

thx for the tips all my best to ya   :)   :P   :>   james says peace Y out

by the way none of your code runs in any kind of compiler not to mention you don't direct the person to what

it was coded on for compiler, see everyone got eyes

 

 

hehehe hohohoho   :)   :P 

Share this post


Link to post
Share on other sites
On 5/25/2019 at 11:01 AM, GoliathForge said:

Hello, I took a look at this briefly. I'm not going to say your code is bad, (whoops) :) but could use some improvement. The area I would attack first is cleanliness. You are sloppy with your bracing. Case in point inside the function named writer...

Here, the variable assignment to x may or may not happen depending the whatever n is supposed to be but y and z always get theirs. 

edit: worse yet, it will only write the first vertex.

my write routine is fine i needed a read routine.

 

ps: watch out you may be c64 coding killers, i have no seen you guyps share code with anyone

as you can see i did share in a real coder im always sloppy in my beta code and beta testing

greets to ATC coders all good ZiNes to you all yes even to the c64 killers 

Don't hate the player,hate the game  Y   peace out   :)

Share this post


Link to post
Share on other sites
Posted (edited)

Guys, maybe you are little too quick with downvotes. Not everybody moves self confident in the internet, especially a beginner may feel uncomfortable and gild that with joking (personal opinion).

------------

That being said, @jakeplow, lets try to keep it serious. @GoliathForge has pointed out that your code is not the best. Good news, there is room for improvement 😉

First, let me say that the technique OP uses is ages old. Like a generation or so. There are beautiful tutorials around, like learnopengl.com and of course many others.

Second, it seems like OP comes from python or so ? This:

 if (n == 0.0)
    x =    verts[0].x;
    y =    verts[0].y;
    z =    verts[0].z;

will in C not do what it is supposed to do. A block in C needs to be put in curly brackets. It would show more clearly if you would format your code, that is a valid objection. Also, posting formatted code somewhat honours the reader as it makes looking over it simpler.

Thirdly, this:

 if (xtc = 1.0)
    xt =    verts[0].x;
    yt =    verts[0].y;
    zt =    verts[0].z;

has the same problem. Plus, you put an assignment in the if where there is supposed to be a comparison. Also, floating point values should not be compared with a simple == as the representation in the computer is not exact enough (only 7 digits).

So, a little course in C (or better C++) would do no damage either. Take your time. Ask your questions, but don't joke at people who try to help. It is irritating 🙂

Sorry for talking old ... now, can you follow the problems with the code that we pointed out ?

 

Edited by Green_Baron
s to y

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!