Trying to setup a graphics C/C++ invironment

Pages: 123
"Yes, you have made a number of mistakes in this thread. Your ego / righteous indignation / whatever is not helping you any."

I'm not sure what that means. My ego is not bigger than I realized I'm clearly not a person who can do all that library compiling stuff and understand what is going on.

"how do I learn to use this software to do cool stuff?"

No, I don't want to learn a specific company software, but generalize so I can learn more math and geometry.

If some software for me is pedagogical to learn I will do my best otherwise I don't care. If I don't understand the basic of "stuff" I can't build on it.

"The only other option / mindset that would prove productive would be to convince others to do the task for you."

Appendrenly i'm not able to write in clear English but my goal is to learn mere math and geometry. I find C++ interesting and I was only trying to do that in C++ but all that library compiling stuff is tilting me.

Thank again for answer.
"the point is that graphics are not seen by the standard committee as being worth standardizing into the language."

I had no idea but that the way it is.

I really like C++ but I think i'm to much of an old dinosaur and must settle with that. Last time I programmed was in the eighties with basic and 6502-assembler (inline) and direct access to screen memory.

Thanks for answer.
"You are right, there are simple 2-d libraries. But you still have to include a few headers and link the library into your project: no such thing exists in the c++ language directly. This is what you are going on about, and doing so is about as effective as going outside and shaking your fist at the sky: it may make you feel better, but it won't teach the universe a lesson or accomplish much."

I would not mind to include headers and I'm doing something similar in basic. I like to take little steps.

Three month ago I did not knows the existence of the unit circle, vectors etc. but after a "trillion" try's I managed to do a function that can calculate drawing or moving in 3D. I have lot of gaps in my math but I'm using graphics to learn and I like it.
I don't need more functionality that graphics.h can provide, but I struggle to find a solution.
1
2
3
4
#include <iostream>
int main() {
  std::cout << "Hello world\n";
}

This program needs only a tiny fraction of the content of "iostream", yet all of that content (which is split into several files) has to be available for us to compile the program. However, we don't need to learn all about the standard iostreams library in order to write the "Hello world" program.

Similarly, you might "just need to draw a dot", but in order to do so you do need rather large and complex framework. C++ itself does not have such framework, but third-party libraries (written in C or C++ or whatnot) do.

Scott Meyers stated in a presentation that C++ is a good language for library writers. For people that create code libraries. There is no point is having libraries, if nobody uses them. There is no point in (re)writing a lot of code, when someone has already made it and shares as a library.


You are right that if you don't understand "the basic stuff", like how to compile a program or use libraries, then you can't write programs that solve your problems.
"You are right that if you don't understand "the basic stuff", like how to compile a program or use libraries, then you can't write programs that solve your problems. "

I don't think I would benefit enough from spending time trying to understand the whys and how’s in compiling libraries. If I just can't add libraries I won't bother for now. I will only use simple graphics and not spend too much time with different libraries that are overkill for my purpose.

I did know how to run 6502 assembler and I disassemble too - that much I understood back then. Actually I remember many instructions and addressing modes and wrote flicker free side scrolling games by programming the video chip 35 years ago.

How much effort will it take to do my example code in C++?

---------------------------------------------------------------------------
REM basictoc 02.04.20 - draw lines throug origin and turning 15 degrees

MODE 22 REM Opens a window with 2048 x 1536 pixels

radius = 400
xpos = 1024
ypos = 768
angle = 15

FOR vinkel = 0 TO 180 -angle STEP angle
x = radius * COS(vinkel*PI*2/360)
y = radius * SIN(vinkel*PI*2/360)
MOVE xpos + x ,ypos + y
DRAW xpos - x, ypos - y
NEXT
---------------------------------------------------------------------------
---------------------------------------------------------------------------
Last edited on
I’m pretty done here.

You asked a question, you got some answers, including a complete, working example in Tcl, which is much better suited to your needs than C++.

But you don’t like the answers, and no one else here seems to want to stop trying to “help” you.

The world won’t bend to work the way you want it to. If you want to learn to use a tool, then you have to learn it on the tool’s terms. Otherwise you are SOL.

Tough beans.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

const double PI = 4.0 * atan( 1.0 );

//======================================================================

void point( vector<string> &canvas, int i, int j )
{
   const int N = canvas.size() - 1;
   if ( i >= 0 && i <= N && j >= 0 && j <= N ) canvas[i][j] = '*';
}

//======================================================================

void line( vector<string> &canvas, int i1, int j1, int i2, int j2 )
{
   if ( i1 == i2 && j1 == j2 )
   {
      point( canvas, i1, j1 );
      return;
   }

   if ( abs( i2 - i1 ) >= abs( j2 - j1 ) )
   {
      if ( i2 < i1 ) { swap( i1, i2 ); swap( j1, j2 ); }
      double slope = (double)( j2 - j1 ) / ( i2 - i1 );
      for ( int i = i1; i <= i2; i++ )
      {
         int j = j1 + round( slope * ( i - i1 ) );
         point( canvas, i, j );
      }
   }
   else
   {
      if ( j2 < j1 ) { swap( j1, j2 ); swap( i1, i2 ); }
      double slope = (double)( i2 - i1 ) / ( j2 - j1 );
      for ( int j = j1; j <= j2; j++ )
      {
         int i = i1 + round( slope * ( j - j1 ) );
         point( canvas, i, j );
      }
   }
}

//======================================================================

int main()
{
   const int N = 80;

   vector<string> canvas( N + 1, string( N + 1, ' ' ) );
   int xc, yc, r;
   xc = yc = r = N / 2;
   for ( int deg = 0; deg < 360; deg += 15 )
   {
      double rad = deg * PI / 180.0;
      int x = xc + r * cos( rad ) + 0.5;
      int y = yc + r * sin( rad ) + 0.5;
      line( canvas, N - yc, xc, N - y, x );
   }

   for ( string s : canvas ) cout << s << '\n';
}

//====================================================================== 
Last edited on
Nice.
@lastchance, that is a rather cool bare-bones "strictly C++" example. Thanks for sharing.

MSVC spits up 6 warnings of arithmetic overflow; lines 31, 34, 41 and 44; but the "star" shows up. Is it supposed to be a star?
The asterisk ('star') is on line 15.

MSVC complains when you implicitly cast between numeric types. You have to either explicitly cast or turn off those specific warnings to get MSVC to shut up.
@Duthomhas, I know why the warnings show up, and how to correct them. If I chose to do so. I simply mentioned MSVC was acting IMO overly pedantic. Arithmetic overflow is not a common warning for the projects I do.

I've recently changed the warning level in my projects. MSVC defaults to /W3, and I've lately been using /W4 for all new C++ projects. Maybe now I'll see overflow warnings more frequently.

There are also conversion warnings, from double to int. More common in my projects, and fixable if I need to.

The entire design looks like a star with radiating filaments, drawn using asterisks. Whatever it is, the design looks like some nice and simplistic ASCII art.
Yes, I always compile with /W4 and write explicit casts to indicate that yes, I very much meant to do the type conversion with potential overflow/underflow/loss of precision/whatever.

Geometric ASCII art challenge?
Err, it was supposed to (roughly) match what the OP wrote in BASIC, since he/she asked "How much effort will it take to do my sample code in C++?". (Draw lines through the origin turning 15 degrees).

In which respect I failed.

But I had lots of fun!
Last edited on
I don't think you failed, you did something artful. And had fun doing it. That is quite a success IMO.

Maybe the OP will learn something as well. I know I did.
"I’m pretty done here.

You asked a question, you got some answers, including a complete, working example in Tcl, which is much better suited to your needs than C++.

But you don’t like the answers, and no one else here seems to want to stop trying to “help” you.

The world won’t bend to work the way you want it to. If you want to learn to use a tool, then you have to learn it on the tool’s terms. Otherwise you are SOL.

Tough beans."


Thanks again!

I think you should not relate to me personally and instead relate to C++ or otherwise stop to comment - please!

You made me think of my friend who failed an exam because had not used the teached way to solve a problem but had used alternative solution and he had the correct answer!

I’ll always try to use what I like or suits me and disregard the rest if I can.

I'm convinced that any issue should questioned and tested from different angles all the time and forever that’s how evolution evolve and disrupted...
"Err, it was supposed to (roughly) match what the OP wrote in BASIC, since he/she asked "How much effort will it take to do my sample code in C++?". (Draw lines through the origin turning 15 degrees).

In which respect I failed.

But I had lots of fun! "

:o)

I really want see this but we can't attach pictures or?
@basictoc,
If you look to the right of a runnable code sample (as in my post) you should see an "Edit & Run" button.
That will take you to cpp.sh, an online editor and compiler. Run it from there and you should see the output.

I think the point that others made is that graphics isn't built into the c++ standard: it would usually be performed (much better) by specialist libraries. In most cases, you shouldn't have to "build" those libraries: just link them in after you compile your code. Some of those libraries don't rely on you programming in c++. I use one because it has near-identical bindings for other languages that I use.

I would get to grips with c++ first and then you would be in a good position to play with external libraries. There have been some good suggestions in this thread.
Last edited on
@lastchange,

Thanks for clearing the subject.

I had to change browser from Tor to Firefox. Output is exactly like my line drawings.

That C++ shell is it possible to get one for off line use - I really like the minimalistic and non disturbing design?

How do you paste formatted code into the thread?

And last question: Why do you not declare x and y outside the for loop?

int main()
{
const int N = 80;

vector<string> canvas( N + 1, string( N + 1, ' ' ) );
int xc, yc, r, x, y;
xc = yc = r = N / 2;
for ( int deg = 0; deg < 360; deg += 15 )
{
double rad = deg * PI / 180.0;
x = xc + r * cos( rad ) + 0.5;
y = yc + r * sin( rad ) + 0.5;
line( canvas, N - yc, xc, N - y, x );
}

for ( string s : canvas ) cout << s << '\n';
}

@basictoc,
You can format code (and other things, like quoting) using the format menu that appears to the right when entering or editing a post. For code tags, paste your code, select it and then click the first item in that format menu.

In c++ it is common to declare variables as close as possible to point of first use. If you declare x and y within the for-loop then they will exist only within that loop ... which is all that you need. Different languages do this in different ways.
"In c++ it is common to declare variables as close as possible to point of first use. If you declare x and y within the for-loop then they will exist only within that loop ... which is all that you need. Different languages do this in different ways. "

Ok in basic I do my best to avoid exactly that - It's very important especially in nested loops to keep calculations outside as much as possible.

So in c++ what ever variables declared inside loops will only be executed one time and the compiler will take care of that...

And the scope stops by the "}" and the variable will be unknown hereafter...
Pages: 123