void GfxGlEngine::drawPicture(const Picture &picture, const int dx, const int dy)
{
   GLuint aTextureID = picture._glTextureID;
   int x0 = dx+picture.get_xoffset();
   int x1 = x0+picture.get_width();
   int y0 = dy-picture.get_yoffset();
   int y1 = y0+picture.get_height();


   // Bind the texture to which subsequent calls refer to
   glBindTexture( GL_TEXTURE_2D, aTextureID);

   glBegin( GL_QUADS );

   //Bottom-left vertex (corner)
   glTexCoord2i( 0, 0 );
   glVertex2f( x0, y0 );

   //Bottom-right vertex (corner)
   glTexCoord2i( 1, 0 );
   glVertex2f( x1, y0 );

   //Top-right vertex (corner)
   glTexCoord2i( 1, 1 );
   glVertex2f( x1, y1 );

   //Top-left vertex (corner)
   glTexCoord2i( 0, 1 );
   glVertex2f( x0, y1 );

   glEnd();
}
Beispiel #2
0
int main (int argc, char *argv[]) {
  ofstream output;
  char in;
  int width, c, d;
  string filename, line;

  if ((argc > 1) && (!strcmp (argv[1], "/?"))) {usage (); exit (0);}
  if (argc > 2) { // Do we have an output file?
    filename = argv[2];
  } else {
    if (argc > 1) {
      filename = argv[1];
      int n = filename.find_last_of('\\');
      filename.erase(n + 1, filename.length() - n);
      filename.append("Enpict.txt");
    } else filename = "Enpict.txt";
  }
  output.open(filename.c_str ());
  if (!output.is_open ()) {
    cout << "Unable to open " << filename << " for writing.\n\n";
    usage (); exit (0);
  }
  Picture pict;
  if (argc > 1) { // Do we have an input file?
    ifstream input (argv[1]);
    if (!input.is_open ()) {
      cout << "Unable to open " << argv[1] << " for reading.\n\n";
      return 0;
    }
    streamsize longest = 0;
    while (input.ignore(numeric_limits< streamsize >::max(), '\n'))
      longest = max(longest, input.gcount());
    pict.set_width (--longest);
    input.clear();
    input.seekg (0, ios::beg);
    while (getline(input, line)) {
      for (string::const_iterator d = line.begin(), end = line.end();
        d != end; ++d) pict.enpict(*d);
      for (int d = line.size(); d != longest; ++d)
        pict.enpict (' ');
    }
    input.close ();
  } else {
    usage ();
    cout << "\nInput the width of your picture : ";
    cin >> width;
    pict.set_width (width);
    cout << "\nStart inputing the picture. All non-space characters will be\n"
      << "treated the same. Input a blank line to quit\n";
    cout << ":"; for (c = 0; c < width; c++) cout << '-';
    cout << ":\n:";
    cin >> ws;
    c = 0; in = cin.get ();
    while (in != '\n') {
      c++; pict.enpict (in);
      in = cin.get ();
      if (c == width) while (in != '\n') in = cin.get ();
      if (in == '\n') {
        while (c++ < width) pict.enpict (' ');
         cout << ':';
         c = 0; in = cin.get ();
      }
    }
  }
  cout << "Encoded picture data for Depicter.c:\n\nstring code =\n\"";
  output << "string code =\n\"";
  string temp = pict.get_code();
  d = 0;
  for (c = 0; c < temp.length ();c++) {
    if ((temp.at(c) == '"') || (temp.at(c) == '\\'))
      {cout << '\\'; output << '\\'; d++;}
    cout << temp.at(c); output << temp.at(c);
    if (!(++d % 77)) {cout << "\"\n\""; output << "\"\n\"";}
  }
  cout   << "\";\nint width = " << pict.get_width() << ";\n";
  output << "\";\nint width = " << pict.get_width() << ";\n";
  output.close ();
  cout << "\nPress ENTER to continue...";
  getline (cin, line);
}