delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/03/15/03:59:03

To: djgpp AT sun DOT soe DOT clarkson DOT edu
From: Mike Piff <M DOT Piff AT sheffield DOT ac DOT uk>
Date: 15 Mar 94 08:49:33
Subject: Graphics and C++
Reply-To: Mike Piff <M DOT Piff AT sheffield DOT ac DOT uk>

I have a program that compilers and runs successfully as a .C program. I
changed it to a .CC program, and tried -lgr_p as a guess, but then I get
undefined reference to 'mcount' lots of times.

Any ideas what I am doing wrong? Also, getkey() isn't accepted any more as a
statement.

(Program appended as a freebie.)

Mike Piff


/* Auto-stereo program---Mike Piff*/
#include <stdlib.h>
#include <stdio.h>
#include <graphics.h>
#include <math.h>

#define EYES 180
#define GROUND (EYES/2)

int WIDTH, HEIGHT,RADIUS;
int same[2000],colour[2000];
int nrfcolours;

int randomColour()
{
  return (int)((16.0*(float)random())/((float)RAND_MAX))%nrfcolours;
}

int ancestor(int i)
{
   if(same[i]==i)
      return i;
   else return ancestor(same[i]);
}

draw3D(int (*z)(int,int))
{
   int x,y,i,j,sep;
   for(y=0;y<HEIGHT;y++){
      for(x=0;x<=WIDTH;x++)same[x]=x;
      for (x=0;x<=WIDTH;x++){
        sep=z(x,y);
        if (((sep%2)==1) && ((y%2)==1)) i=x-((sep + 1)/2);
        else i=x-(sep/2);
        j=i+sep;
        if((i>=0)&&(j<WIDTH))
        {
          i=ancestor(i); j=ancestor(j);
          if(i<j) same[i]=j;
          else same[j]=i;
        };
      };
      for(x=WIDTH-1;x>=0;x--)
      {
        if(same[x]==x) colour[x]=randomColour();
        else colour[x]=colour[ancestor(x)];
        GrPlot(x,y,colour[x]);
      };
   }
}

int sphere(int x,int y)
{
  int r,R,a,b;
  a=WIDTH/2; b=HEIGHT/2;
  x=x-a; y=y-b;
  r=(x*x+y*y); R=RADIUS*RADIUS;
  if(r<R) return (0.9*GROUND - sqrt(R-r)/10);
  else return GROUND;
}

main (int argc, char *argv[])
{
  /* srandom(time());*/
  char buf[100];
  char **tmp;
  if (argc==1) nrfcolours=2;
  else {
    nrfcolours=(int)strtol(argv[1],tmp,10);
    if(nrfcolours<2) nrfcolours=2;
  }
  GrSetMode(GR_default_graphics);
  WIDTH = GrSizeX();
  HEIGHT = GrSizeY();
  RADIUS=HEIGHT/2;
  draw3D(sphere);
  getkey();
  GrSetMode(GR_default_text);
  /*printf("WIDTH=%d, HEIGHT=%d\n",WIDTH,HEIGHT);*/
}


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019