how to use graphics???

M

mohi

hello everyone,
we have a course on computer graphics and they are teaching various
algorithms to draw lines and circles and all of them
require the classical putpixel() function in c++. As i have learned
from web sources that this function is no longer in existence .is that
true?? and if so what can i use that can provide the same
functionalities, i mean is there a new form of that function or what
should i do??

i use gnu g++ on command line.



thank you very much.
mohan gupta
 
J

joseph cook

hello everyone,
we have a course on computer graphics and they are teaching various
algorithms to draw lines and circles and all of them
require the classical putpixel() function in c++. As i have  learned


You should really just ask your professor what platform he expects you
to use.

Joe Cook
 
T

tni

Alf said:
Note: the above doesn't compile cleanly with Visual C++. That's because
the PNG i/o is really really horrible code (adding a notch of
horribility (whatever) to the degree present in the main library).

> [...]
>
Especially the diagnostic about 'setjmp' makes alarm bells go off in my
brain.

It's not like they have much choice. Like IJG libjpeg, libpng uses an
error handler function (that can be provided by the client) that's not
supposed to return. They could throw an exception, but that's even worse
unless libpng was compiled as C++.

However, the way they are doing it is completely broken and will at
least result in memory leaks.
 
J

Juha Nieminen

tni said:
It's not like they have much choice. Like IJG libjpeg, libpng uses an
error handler function (that can be provided by the client) that's not
supposed to return. They could throw an exception, but that's even worse
unless libpng was compiled as C++.

The libpng library is a horrible, horrible monstrosity, even for a C
library. I wouldn't recommend using it even if you were writing a C
program, except that for some reason there doesn't seem to be any good
popular alternative out there.

It *is* possible to implement easy-to-use clean libraries even in C.
Just look at zlib for instance. Why they decided to make libpng so
horrible is beyond my grasp.
 
J

Juha Nieminen

mohi said:
hello everyone,
we have a course on computer graphics and they are teaching various
algorithms to draw lines and circles and all of them
require the classical putpixel() function in c++. As i have learned
from web sources that this function is no longer in existence .is that
true?? and if so what can i use that can provide the same
functionalities, i mean is there a new form of that function or what
should i do??

i use gnu g++ on command line.

You don't specify which OS you are on, but if it has the GTK+ devel
libraries installed, you can use the simple DrawWindow library available
at this page for simple point, line and circle drawing on a graphical
window. It's very easy to use:

http://www.cs.tut.fi/~tgraf/harjoitustyot/harkka1/

(The library also has simple support for mouse input, so your app can
be interactive.)
 
A

aku ankka

* mohi:
hello everyone,
we have a course on computer graphics and they are teaching various
algorithms to draw lines and circles and all of them
require the classical putpixel() function in c++. As i have  learned
from web sources that this function is no longer in existence .is that
true?? and if so what can i use that can provide the same
functionalities, i mean is there a new form of that function or what
should i do??
i use gnu g++ on command line.

You might use the Boost library.

However, the documentation and code seems to be the winner in a contest of
obfuscation and Bad Programming Habits.

I cooked up a usage example, shown below, and if this serves your needs then you
won't have to confront the full horror of that library! :)

Disclaimer:

I haven't worked with the graphics part of Boost before, so it may very well be
that I'm using this in a non-idiomatic way!

<code>
// Visual C++ sillywarnings:
#ifdef  _MSC_VER
#   pragma  warning( disable: 4100 )        // unreferenced argument
#   pragma  warning( disable: 4127 )        // constant conditional expression
#   pragma  warning( disable: 4512 )        // can't gen. assignment operator
#endif

#include <boost/gil/gil_all.hpp>
#include <boost/gil/extension/io/png_dynamic_io.hpp>

class ImageData: public boost::gil::rgb8_image_t
{
public:
     typedef boost::gil::rgb8_image_t     Base;

     ImageData( size_t w, size_t h ): Base( w, h ) {}

     boost::gil::rgb8_view_t view()
     {
         return boost::gil::view( *this );
     }

};

class Image
     : protected ImageData                   // Image data, must be first (init)
     , protected boost::gil::rgb8_view_t     // Image operations
{
private:
     typedef boost::gil::rgb8_view_t     ImageOps;
     typedef boost::gil::rgb8c_view_t    ConstImageOps;

     friend class ConstImageOps;

public:
     typedef ImageOps::reference     PixelRef;

     Image( size_t w, size_t h )
         : ImageData( w, h )
         , ImageOps( ImageData::view() )
     {}

     PixelRef operator()( size_t x, size_t y )
     {
         return ImageOps::eek:perator()( x, y );
     }

     ImageOps const& view() { return *this; }
     ConstImageOps view() const { return static_cast<ImageOps const&>( *this ); }

};

typedef boost::gil::rgb8_pixel_t    ColorRGB;

int main()
{
     Image   image( 42, 42 );

     for( int x = 0;  x < 42;  ++x )
     {
         image( x, x ) = ColorRGB( 0xff, 0, 0 );
     }
     boost::gil::png_write_view( "an_image.png", image.view() );}

</code>

Note: the above doesn't compile cleanly with Visual C++. That's because the PNG
i/o is really really horrible code (adding a notch of horribility (whatever) to
the degree present in the main library).  Looks like this:

<diagnostics>
c:\projects\lib\boost\boost_1_35_0\boost\gil\extension\io\png_io_private.hp­p(157)
: warning C4611: interaction between '_setjmp' and C++ object destruction is
non-portable
c:\projects\lib\boost\boost_1_35_0\boost\gil\extension\io\png_io_private.hp­p(319)
: warning C4611: interaction between '_setjmp' and C++ object destruction is
non-portable
c:\projects\lib\boost\boost_1_35_0\boost\gil\extension\io\png_io_private.hp­p(340)
: warning C4244: 'argument' : conversion from
'boost::gil::image_view<Loc>::y_coord_t' to 'png_uint_32', possible loss of data
         with
         [
             Loc=boost::gil::rgb8_loc_t
         ]

c:\projects\lib\boost\boost_1_35_0\boost\gil\extension\io\png_io.hpp(202) : see
reference to function template instantiation 'void
boost::gil::detail::png_writer::apply<View>(const View &)' being compiled
         with
         [
             View=Image::ImageOps
         ]
         vc_project.cpp(65) : see reference to function template instantiation
'void boost::gil::png_write_view<Image::ImageOps>(const char *,const View &)'
being compiled
         with
         [
             View=Image::ImageOps
         ]
c:\projects\lib\boost\boost_1_35_0\boost\gil\extension\io\png_io_private.hp­p(340)
: warning C4244: 'argument' : conversion from
'boost::gil::image_view<Loc>::x_coord_t' to 'png_uint_32', possible loss of data
         with
         [
             Loc=boost::gil::rgb8_loc_t
         ]
</diagnostics>

Especially the diagnostic about 'setjmp' makes alarm bells go off in my brain.
But hey, it's part of Boost. So even if it's not perfect yet, in fact very far
from perfect, it'll presumably be fixed, at least so it compiles cleanly with no
warnings.

Just disregard all those warnings  --  if you get any with g++.

Cheers, & hth.,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Both libpng and jpeglib use setjmp internally and that would require
someone with balls to do code review.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top