Math Functions graph in c [closed] - c

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I'm new here, I searched for any related post like my question and I found nothing
I have a project to create a math function graph in a console like f(x)=ax^2+bx+c the user give me a b c and I draw the function.
Someone told me that there are a library called graphic.h that help me with that
so if someone can help me, I'm not finding anything about graphic.h and my project
And if there are another library or anything that could help
Thanks

Sorry for incomplete answer but you have incomplete question so it is impossible to answer ...
What environment you have to use ? You wrote console but what compiler and OS ? because graphics is very different for each
DOS
many schools still use DOS console apps which is not the same as win or linux console. In DOS there is graphics.h which switch to gfx video mode and then you can use CGA/EGA/VGA and sometimes VESA graphics. Haven't done anything in it since Turbo Pascal 7.0 few decades ago.
for DOS I am using direct VGA/VESA access instead (works on win32 too) but anyway look here and here for info about graphics.h with examples.
graphics.h stands for BGI (Borland Graphics Interface) but you need CGA/EGA/VGA or VESA for proper functionality. Most gfx cards emulate them so that should be no problem just do not expect any arbitrary pixel or color resolution. It can handle 640x480x16 or 320x200x256 and the rest depends on your HW. This lib is native only to ancient Borland/Embarcadero compilers so you will find it somewhere in include path so use < > not " " !!! (you do not need to copy it to your project).
#include <graphics.h>
Windows
You have to create graphics window by WinApi or by IDE of your programing language and then you can use GDI which is part of WinAPI and most compilers have libs for it natively.
linux or different GUI OS
I do not code for such so I do not know exactly but should be similar to Windows
OpenGL (any GUI OS and also sometimes DOS with proper drivers)
if you use OpenGL then you can find tons of examples how to create gfx window + OpenGL and also OpenGL GLUT (OpenGL utilities) have functions that take care of windows stuff. You just code code for events like keystroke, mouse move, redraw ...
google NeHe OpenGL tutorials ... not my favorite but beginners like it
Look here for some more info
Now for the function plot
clear gfx screen
create for loop from xmin to xmax
compute y value for each x
do not forget to scale and offset x,y values to fit your gfx area !!!
draw line from previous to actual point
with different color than clear ...

Related

Going from console to win32 applications [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
After some time coding in c in a simple console, I decided I wanted to try and code an actual Win32 application. However, upon selecting the option, the sheer amount of unknown code that surfaced on my IDE (Visual Studio 2013) just to open a blank window was overwhelming, as I don't understand half of it's meaning or even what to do, since, even simple printf commands yield no result... Can someone point me to a way to understand the differences between console and application? Or at least someway I can insert my current coding knowledge in an application environment?
Working with the Windows API can be quite the experience for a newcomer. The act of opening a window does, certainly, involve a lot of boilerplate code. The good news is a lot of that boilerplate rarely changes, and when it does it'll be for very special circumstances that you can go research. That's why Visual Studio spits the whole mess out for you by default.
There are plenty of resources to learn with, including Microsoft itself: https://msdn.microsoft.com/en-us/library/bb384843.aspx
To help situate you, understand that a lot of what you're looking at that's probably confusing are typedefs used on primitive types. This helps maintain backwards compatibility with programs created for older versions of Windows, and adds semantic meanings to types. A lot of the preprocessor stuff you see in header files is actually conditional compilation - it's checking what environment you're compiling in, what version of Windows, etc. and then providing the correct typedefs so that what actually compiles works on the desired Windows platform. Stuff that's greyed out in VS2013 is stuff that Intellisense sees isn't going to be compiled based on the current #defines and a lot of it may be relatively ancient. A big part of the Windows API for a long time was a strong desire to not break backwards compatibility. This was a huge advantage for Windows, because it means my program you wrote for Windows 3.1 isn't going to be hosed by Windows 95 rolling out. Or XP, 2000, Vista, 7, 8, 10, etc. It does mean a lot of stuff makes it into the API and stays there.
They try to hide a lot of that in the headers, but you'll also see deprecated input variables to functions and the like (this parameter should always be NULL...etc), and you just have to read the documentation. Thank the internet.
For example, an LPCSTR is just a const char*, but the LPCSTR signifies that it's a null-terminated constant string. In fact, you may see that's it's not a const char*, but a CONST CHAR* where CONST and CHAR are #defines themselves to make sure the correct keywords and types are used. In your case it'll probably end up being just normal const char*.
My suggestion, rather than diving into about as complicated a C-API as possible, is to look at something like SDL. SDL is a much simpler C API designed to provide an interface to the operating system's windowing, graphics, and input, while hiding the dirty details of the API, be it Windows, Mac, or Linux. https://www.libsdl.org/
It uses openGL for its graphics. If you're making any kind of game you'll be using some kind of graphics API to talk to the video card. The native Windows graphics API is DirectX, but openGL is the very commonly used cross-platform API. Both APIs allow you to make use of a computer's video hardware to render graphics.
Edit: I'll add, since I went off and voiced an opinion on libraries, which is why these types of questions are probably frowned upon, that I think it's fair to say that SDL is the de facto standard for C third-party multimedia libraries. Also commonly mentioned is SFML, which provides much the same functionality but is more object-oriented and written in C++.
In Visual Studio, when you create a win32 app project, click on next, and click on empty project. This will eliminate all the stuff that Visual Studio creates for a win32 app, but then you start with no files. You'll probably want to start with some simple example C program for windows from a book or web site.

graphics program by OpenGL without windows programming [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I want to do graphics program by OpenGL. But I don't have any experienced in windows programming. Any suggestion?
See these links
lazy foo tutorial for SDL to simplify some file and inputs handling
SDL and OpenGL
Kore engine uses Opengl and SDL and is open source
Kore Engine wiki Some more info on the Kore Engine
My own project using SDL and OPENGL host on Google code
Note that you'll need to code in C++ with those links
EDIT:
I tried GLUT and SFML, and both are easier to use than SDL and OpenGL alone.
GLUT is pretty straightforward but is limited in its scope.
SFML brings the good things of SDL and OpenGL, but with a nice C++ interface instead of the old C interface of SDL and raw OpenGL calls (which are still possible to do). Big performance gain out of the box for the same project, SFML is just better optimized than my own code with SDL.
But I don't have any experienced in windows programming. Any suggestion?
Well, you need to create a window somehow, so that the user can see the beautiful pictures you'll draw using OpenGL. But you're right: Opening a window and creating a OpenGL context is tedious, no matter which OS you're doing it on (the most simple one would be probably NSOpenGLView of MacOS X).
Luckily there are some libraries that abstract away the OS dependent parts of creating a window and creating and attaching a OpenGL context to it.
GLUT is probably the oldest one of those. I discourage using the original GLUT and recommend to use FreeGLUT or OpenGLUT instead, as those are actively maintained. They are easy to use. But GLUT don't give you control over the event loop which essentially means, it's ill suited for creating games.
SDL is actually a whole bunch of sub-libraries, the main library providing creating of windows. Also provides OpenGL support, but has not been tailored for it. Personally these days I'd use SDL for everything but creation of a OpenGL window. But it's fine for audio, loading graphics and such.
GLFW is IMHO one of the nicest OpenGL frameworks out there. It has a well designed API, gives you full control over the event loop and is actively maintained. Also it focuses on exactly one task: Create a OpenGL window and provide a message pump for user input.

What simple C graphics library would you recommend? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed last year.
Improve this question
I'm learning C and I would like to start graphics programming, but start it simple, without spending hours just to understand what functions will I need.
I would like something to draw pixels, squares, maybe sprites, simple stuff, like in BASIC.
I tried SDL and got overwhelmed very quickly. Same with Allegro, it's hard to get it to work on Xcode 4 and documentation is lacking.
Maybe there is some custom one? Also would be nice if it works on Mac OS.
Any book recommendations are welcome, like simple C graphics programming or game programming, whatever.
If SDL is overwhelming, perhaps graphics programming is not the place to start in C. If you want to get familiar with the concepts involved in coding up graphics, try it in a higher level language like Python (with pygame or pyglet.) Most high-level languages have good bindings to graphics libraries. If you really want to learn C by writing games, maybe something more text-oriented (ncurses-based?) is appropriate.
Once you understand the fundamental idioms of graphics programming, applying them to different languages becomes much easier. You'll be able to go from pygame to SDL in C without too much extra pain beyond that inherent in going from Python to C.
I'd go for QuickCG. Here you can find sources and some tuts.
The best you can use at least which is both portable and now almost an industry standard, simple graphics can be done using OpenCV. This is not limited to just drawing lines or primitives, or should I say simple graphics, I have used it for industry standard image processing products and computer vision problem solving. This will be fun if you start learning it. OpenGL is also another place to start. It might well suit what you want. Mostly related to graphics, rather than computer vision or image processing
Another option would be to investigate the Postscript language to get a feel for the stencil/paint image model. And then you could more easily get started with Cairo which implements the same model. A big advantage to the stencil/paint model is device independence. With Cairo you can perform the same drawing commands to output to a window, an in-memory pixmap, or a pdf file writer.
"g2 graphics library" is the most simple. The programming language is C. But does not support "only" 64 bit systems (it supports 32 bit like Mac OS Mojave, and Ubuntu, have not checked up with Windows MSYS MinGw). To create User Interfaces i recommend FLTK (Fast Light Toolkit) with the UI-builder Fluid.
https://sourceforge.net/projects/g2gl/
https://www.fltk.org/software.php

A Simple, 2d cross-platform graphics library for c or c++? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
As in title, i need a 2d graphics library that is cross-platform, and provides simple functions, like in Basic; essentially, i only need to paint a pixel a certain color-I do not need hardware acceleration, or any kind of 3d support. I've found a couple ones, but they're not cross-platform.
Anyone knows a solution for me?
What about SDL?
Perhaps it's a bit too complex for your needs, but it's certainly cross-platform.
Am I missing something to wonder why noone suggests OpenGL? To use it for 2d would be very simple. The OP only wants to color a pixel. It doesn't get simpler than glBegin/glColor/glVertex/glEnd.
Qt 5
GTK+
Cairo
and many many more ...
[In no particular order.] However, if you have any other requirements, let us know. BTW: I am not just posting results of a Google query here, I have used all of these (and SDL -- wrote my first few games in SDL :) and I'd say without a set of requirements, it's very difficult to choose among the ones listed.
Heavy-weight:
GTK
QT
WxWidgets
Lightweight:
FLTK
Fox
Tk
Lua IUP
Ultimate++
dlib
Drawing frameworks without GUI widgets:
SDL
Cairo
http://www.allegro.cc/
http://en.wikipedia.org/wiki/Allegro_library
One neat engine I came across is Angel-Engine. Info from the project site:
Cross-Platform functionality (Windows and Mac)
Actors (game objects with color, shape, responses, attributes,
etc.)
Texturing with Transparency
"Animations" (texture swapping at defined intervals)
Rigid-Body Physics
A clever programmer can do soft-body physics with it
Sound
Text Rendering with multiple fonts
Particle Systems
Some basic AI (state machine and pathfinding)
Config File Processing
Logging
Input from a mouse, keyboard, or Xbox 360 controller
Binding inputs from a config file
Python Scripting
In-Game Console
Some users (including me) have succesfully (without any major problems) compiled it under linux.
I would recommend DISLIN. It's cross platform, has support for many languages, and has very intuitive naming of routines.
Also, just noticed that nobody mentioned PLPLOT, also cross platform, multi lingual ...
Picasso graphic library you can used: cross platform
https://code.google.com/p/picasso-graphic/
A cross platform 2D graphics library for .Net is The Little Vector Library
You could use it in conjunction with Unity 3D (recommended) or Xamarin, for example, to create 2D graphics on a variety of platforms.

Where can I find a simple graphics C library for writing directly onto a frame? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I need a simple graphics C library to use on a device where I will be writing directly to the frame.
The frame is located in regular memory.
There is no graphics acceleration hardware.
Nothing fancy. I just want to be able to draw lines, circles, OSD stuff like strings as well.
It would be nice to have functions that use good, lean algorithms (my CPU is an ARM9 running at 400MHz).
What are some recommendations for this?
For very simple needs (lines, circles, polygons, text) I have always just made my own. Check out bresenham's algorithm for lines and circles, Wu's modifications for antialiasing on circles and lines.
Gimp will output C code for images, which is what I do for fonts, and drawing them is pretty easy. I have used anti-aliasing (gimp --> grayscale, use the grayscale value as the alpha), but haven't done proportional fonts. They aren't much harder, and can make the display a bit nicer, but I haven't needed them yet.
Polygons are simply multiple lines, and filled polygons are quite fun to implement.
It's not a lot of work, and you'll grow from the experience.
If, however, you decide you want to render SVG or some other complex vector language, then a library is in order. But for simple things, this isn't complex.
-Adam
I'd like to second OpenGL, especially the OpenGL|ES variant.
Here is a link to a Software based OpenGL-Renderer: http://sourceforge.net/projects/ogl-es
I've spend the last three years writing commercial software rasterization codes on ARM9 and similar processors, so I think I can comment on use of cairo and other high level APIs:
They work very well and are incredible powerfull, but on a target as limited as an ARM9 you will never be happy with the performance. The graphic libs are written with your typical Desktop PC in mind, and they trade precision for performance. This is nice for high quality SVG rendering, but to slow on a humble ARM.
The Vincent OpenGL|ES I've suggested above has a on the fly dynamic code generation engine for ARM-CPUs in place, so you get almost the performance of hand-optimized assembler code.
If you can limit yourself to just one bitmap-format, just two blend-modes and a hand full of rendering primitives you may get better performance by writing a dozen of render-routines yourself. Depending on your experience and requirements that can take anything from two days to a month though..
Cairo is pretty powerful and easy to use. I think Mozilla uses it as the basis for the <canvas> element and the SVG renderer.
From your requirements it appears you need something like an embedded framebuffer library (or whatever it is called). I played around with some of the following a few years back for an embedded browser (which didn't make it to the market). Unfortunately, I can't remember much to give you any analysis. Have a look:
DirectFB
GTK/X (or a port using directFB)
Cairo (as another poster has suggested -- this is very powerful)
Also, this article may be of interest.
Try SDL. From the web page:
Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer. It is used by MPEG playback software, emulators, and many popular games, including the award winning Linux port of "Civilization: Call To Power."
OPenGL has a set of 2d functions, not sure if it is too bloated for you or if it can be trimmed down. It is written in C, at least.
I found the Adafruit GFX library to my liking.
Very very simple and basic:
https://github.com/adafruit/Adafruit-GFX-Library

Resources