Academic Tutorials



English | French | Portugese | German | Italian
Home Advertise Payments Recommended Websites Interview Questions FAQs
News Source Codes E-Books Downloads Jobs Web Hosting
Chats

Graphics
Graphics Introduction
Graphics Printmaking
Graphics Photography
Graphics for Web
Computer graphics
Computer graphics II
Graphics C++, SDL
Graphics QuickCG
Graphics Light and Color
Graphics Color Model
Graphics Image
Graphics 2D Drawing
Graphics Flood Fill
Graphics Clipping
Graphics Fractals
Graphics Sierpinski
Graphics Julia
Graphics Fire Effect
Graphics Tunnel Effect
graphics Raycasting
Graphics Raycaster
Graphics Floor & Ceiling
Graphics Sprites
Graphics Filtering
Graphics Fourier Trans
Graphics FT on Images
Graphics DC Component
Graphics Texture Gen..
Graphics Random Noise
Graphics Clouds

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
CSS 1.0
CSS 2.0
HLML
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
CVS
Python
Apple Script
PL/SQL Tutorial
SQL Server
PHP
.NET (dotnet)
Microsoft.Net
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
VC++
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Photoshop Tutorial
Gimp Tutorial
Matlab
Gnuplot Programming
GIF Animation Tutorial
Scientific Visualization Tutorial
Graphics
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Weblogic Tutorial
SEO
Web Site Hosting
Domain Name
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Eclipse
J2ME
JBOSS
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Cobol
Assembly Language
Mainframe
Forth Programming
Lisp Programming
Pascal
Delphi
Fortran
OOPs
Data Warehousing
CGI Programming
Emacs Tutorial
Gnome
ILU
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills
Database Tutorials
Oracle
MySQL
Operating System
BSD
Symbian
Unix
Internet
IP-Masquerading
IPC
MIDI
Software Testing
Testing
Firewalls
SAP Module
ERP
ABAP
Business Warehousing
SAP Basis
Material Management
Sales & Distribution
Human Resource
Netweaver
Customer Relationship Management
Production and Planning
Networking Programming
Corba Tutorial
Networking Tutorial
Microsoft Office
Microsoft Word
Microsoft Outlook
Microsoft PowerPoint
Microsoft Publisher
Microsoft Excel
Microsoft Front Page
Microsoft InfoPath
Microsoft Access
Accounting
Financial Accounting
Managerial Accounting
Network Sites


Computer Graphics Tutorial


Previoushome Next







Computer Graphics Tutorial


A D V E R T I S E M E N T



C++, SDL and QuickCG


An SDL codebase is given with this tutorial, called QuickCG. All the C++ code in the articles uses QuickCG and its functions to draw graphics on the screen.

This page will explain how to use QuickCG to get the examples working. Information is provided to get SDL and QuickCG working in the DevC++ IDE, as well as how to do ith with g++.

Then a few examples of scripts for QuickCG follow.

And finally, tables are given with all the QuickCG functions, some C++ functions and operators, QuickCG and SDL datatypes, and all the SDL names for keyboard keys.

SDL is an API that can handle graphics, audio, keyboard, mouse and joystick input on many platforms, including Windows and Linux. SDL can also be used to initialize and use OpenGL for 3D graphics. The codebase of this tutorial uses SDL for it's graphics and input, but the rest of the focus of this tutorial is on the graphics algorithms, and not SDL. In this tutorial SDL's functions are rarely used directly (but through QuickCG instead), though it's always handy to learn a thing or two about SDL if you'd like to make some games with it.

QuickCG was designed specifically for this tutorial, to be as easy to use and as universal as possible and to feel a bit like a scripting language. QuickCG includes functions to set up the screen, draw pixels and 2D primitives on it, handle input, do color model conversions, print texts and numbers on the screen using a built in font, load pictures, etc... QuickCG is less useful for making actual games because it's not really optimized.
A full list of all functions it contains is further on this page.


DevC++


 


This section is for if you want to use DevC++ in Windows to run the examples.

DevC++ is a free IDE for Windows, that uses the compiler gcc 3.2 or later. For help on using DevC++, I suggest you check out the help files, try to open and compile some of the included examples, check out the bloodshed.net website, or just read on here.

This chapter is only for Windows users who want to be able to compile QuickCG and the examples with the free DevC++ IDE. It's also perfectly possible to use SDL and QuickCG on other platforms, but for now that's not explained here. If you don't know how, use the SDL site or google to find out how to install it with your compiler, and then make a new project in your compiler and add the .cpp and .h files of QuickCG to it.

If you don't have the newest version of DevC++ installed yet, follow these steps to get it up and running with SDL. If you have it installed, but not yet the SDL developer libraries, start at step 2).

It's not very easy to install SDL for DevC++, but it is possible to get the newest version of SDL to work with DevC++, if you follow these steps very carefully:

1) download and install the latest version of DevCpp from http://www.bloodshed.net/dev/devcpp.html
2) download the latest version of SDL from http://www.libsdl.org/: download the Development Libraries for Mingw32 (under Windows) and the runtime libraries for Windows. You may need WinRAR to be able to unpack the .tar.gz files.
3) The runtime library contains the file SDL.DLL, put it either in your C:\Windows\System32 folder, or put one in the folder of your compiled program, and don't forget that you always have to include SDL.DLL with your program if you want other people who don't have the file to run it. Programs compiled for the newest version of SDL won't work with older versions of the DLL.
4) Unpack the SDL developer files, but not yet inside the DevC++ folder, put them in another folder.
5) Copy the SDL folder of the development files, which is inside the folder include, into the include folder of DevC++ (so that all the SDL header files are in DevC++ under include/SDL)
6) Copy the files in the lib folder of the development files, into the lib folder of DevC++.

Now you have installed DevC++ with SDL! You still need to know how to make a working project that uses SDL though. The other files in the development package include the full SDL documentation, example and tests, and the binaries. Your DevC++ folder structure should now look like this, where the SDL folder is new, and the lib folder contains new files from the SDL development package.

If you use the SDL codebase (QuickCG) provided with the tutorial, unzip it to your code folder (that folder where you store all your DevC++ projects and code in, which is hopefully not in the unreliable My Documents folder of Windows), and just open it's *.dev file with Dev-C++, and it should compile and run correctly. To compile it, use "Execute -> Compile" from the menu. The exe file will appear in the same folder as where your code is located. You can run it with "Execute -> Run". You can also compile&run your projects by pressing F9. If it doesn't work, look a bit further for a list of possible solutions. It's highly recommended that you use QuickCG for this tutorial, because the rest of the tutorial focuses on the commands of it and not on the actual SDL itself.

But if you want to make a new SDL project of your own in DevC++ (not needed for this tutorial):

7) Start up DevC++ and make a new project. Add any .cpp and .h files you need to it.
8) In the menu Project open Project Options and locate the setting for Linker Commands (in DevC++ 5 Beta 8.10 it's under Parameters) and add:
-lmingw32
-mwindows
-lSDLmain
-lSDL
Note that the order IS important! If you put -lSDL first and then -lSDLmain it won't work!



9) In your cpp files, #include <SDL/SDL.h>
10) Under Linker options, turn off the console.
11) Under Compiler in Project Options, and under the general Compiler Options, turn on all settings for optimizations, because they really make a big difference! You can also add -s to the linker parameters to reduce the size of the *.exe files it generates, if you don't do this, the exe's will be full of debugging information, even if the debugging setting is off (as of DevC++ 5 Beta 8.10)

If you're getting compiler errors when trying to compile your SDL project, here are some things to check:
 

  • Did you follow steps 1-6 or 1-11 correctly, in the correct order? Read every detail?
  • Did you #include the SDL.h header file in the code?
  • Is the SDL.h file in the correct folder of DevC++? (if it's in the SDL folder inside include, you have to include it with #include "SDL/SDL.h", if it's directly in the include folder, use #include "SDL.h")
  • Are all the other SDL header files in the correct folder of DevC++?
  • Are the SDL library files (libSDL.a and libSDLmain.a) correctly in the lib folder of DevC++?
  • Did you put -lSDLmain and -lSDL in the correct order in the Linker parameters?
  • Are the options -lmingw32 -mwindows -lSDLmain -lSDL correctly in the linker parameters, and not wrongly in the compiler parameters?
     
  • Did you make a main function?
  • Try if the FAQ on the http://bloodshed.netorhttp://www.libsdl.org site answer your problem. There's info about DevC++ in the faq from libsdl.org. These sites also have search functions.
  • Try searching for some keywords from the compiler or linker error with google. You might find forum posts which describe your problem.
  • If you have a different version of DevC++ than version 5 Beta 8.10, things might be different (I encourage using the newest version, there may be more recent information available than this tutorial). Try to find the correct way to tell the linker to add the files libSDLmain.a and libSDL.a, and give the linker the options -lmingw32 and -mwindows, and the correct folders for include and library files.
  • If you're trying to get your own project to work, try if QuickCG that you can download with this tutorial works correctly (open it's *.dev file, compile and run it). If it does, but your own project doesn't, try giving your project the same settings as the project from QuickCG.
Once you got it to work, you can run example code of the tutorials by opening the quickcg.dev file with DevC++ and going to main.cpp file where you can enter the code. Here's a screenshot of the main.cpp file after opening it.



 

g++


 


This section is for if you want to use g++ to run the examples.

With g++ it's quite easy: place all .cpp and .h files of QuickCG in the same directory, put the example code of tutorials in the main.cpp file, and then you can compile it with the following command:

g++ *.cpp -lSDL -O3

The -O3 is optional if you want compiler optimization. The -lSDL lets it link to SDL. This requires you to have SDL installed on your distro (look for sdl and sdl-devel packages or similar).


Using QuickCG


QuickCG currently exists out of the following code files and a .dev file:
 

  • QuickCG.cpp: this contains all the functions of QuickCG
  • QuickCG.h: #include this header file in all *.cpp files where you want to use QuickCG's functions
  • Q3DMath.cpp: contains 3D functions (currently not used anymore in the tutorial)
  • Q3DMath.h: #include this if you want to use the 3D functions and classes (currently not used anymore in the tutorial)
  • main.cpp: in this file you can type the code of the examples of this tutorial. Leave the #includes at the top of the file intact to be able to run all examples.
  • QuickCG.dev: this is the project file for DevC++ that contains all necessary settings, if you don't use DevC++ you can remove this file and make your own project that uses the .cpp and .h files.
     
The main.cpp file file is where you can put the code of the examples of this tutorial. If no main function is mentioned in a code example, make one yourself and put the example inside the main function.

There's normally a small example included in the main.cpp file:

 

	int main(int argc, char *argv[]) 
{ 
    screen(256, 256, 0, "Small Test Script"); 
    for(int x = 0; x < w; x++) 
    for(int y = 0; y < h; y++) 
    { 
        pset(x, y, ColorRGB(x, y, 128)); 
    } 
    redraw(); 
    sleep(); 
}
      

Here's what it does:
 
  • The screen function will create the graphical window, with a resolution of 256*256 pixels, windowed, and with the caption "Small Test Script". You always have to use the screen function at the start of any program, or you'd be drawing pixels on a non existing window.
  • Next comes a double for loop, which goes through every pixel of the window: w and h are global variables that contain the width and the height of the window.
  • Inside the for loops is the function pset. This function will plot a pixel at location x, y with RGB color x, y, 128. This means the red color component will depend on the location x of the pixel, the green color component will vary with the location y of the pixel, and blue component will always be 128.
  • After the loop comes the function redraw. You always have to use this function before you'll be able to see any new pixels you've drawn. The redraw function is relatively slow, so do NOT call it after every single pixel, but only once after all pixels of the screen have been drawn.
  • Finally, the sleep function will let the program pause until you press any key. If the sleep function wouldn't be there, the program would close immediately and you wouldn't be able to see the result.
If you compile and run this code, the output will be as follows:



Now try to change the program a bit, for example, copypaste this instead into the main function (use CTRL+SHIFT+i to indent it in DevC++5):

 
int main(int argc, char *argv[]) 
{
    screen(256, 256, 0, "Small Test Script"); 
    for(int x = 0; x < w; x++) 
    for(int y = 0; y < h; y++) 
    { 
        pset(x, y, ColorRGB(0, 128 + 128 * sin(x / 8.0), 0)); 
    } 
    print("Hello World!"); 
    redraw(); 
    sleep(); 
}
      

What has changed, is that you'll now see a green sine function pattern, and a text "Hello World!", because putting text on the screen is what the print function does. The output should look as follows:



Now another, easier, example:

 
int main(int argc, char *argv[]) 
{ 
    screen(256,256, 0, "A Face!"); 
    drawDisk(128, 128, 100, colorRGB(255, 128, 200)); 
    drawDisk(88, 100, 10, colorRGB(0, 0, 255)); 
    drawDisk(168, 100, 10, colorRGB(0, 0, 255)); 
    drawLine(88, 150, 168, 150, colorRGB(255, 0, 0)); 
    redraw(); 
    sleep(); 
}
      

The drawDisk command will draw a filled circle at the given position, with a certain radius and RGB color. The disk function is called 3 times: to draw a face, and two eyes.
The drawDine command will draw a line.
The redraw() and sleep() commands are again needed so that the new pixels will show up, and so that the program won't close immediately.
The output should look like this:



A full list of all commands is below, and the next chapter is full of easy examples of all functions to learn working with QuickCG.



© Lode Vandevenne. Reproduced with permission.


Be the first one to comment on this page.




  Graphics eBooks
More Links » »
 
 Graphics FAQs
More Links » »
 
 Graphics Interview Questions
More Links » »
 
 Graphics Articles
More Links » »
 
 Graphics News
More Links » »
 
 Graphics Jobs
More Links » »

Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Previoushome Next

Keywords: Computer Graphics Tutorial, Graphics, Graphics, Graphics tutorial, Graphics tutorial pdf, history of Graphics, learn Graphics

HTML Quizzes
HTML Quiz
XHTML Quiz
CSS Quiz
TCP/IP Quiz
CSS 1.0 Quiz
CSS 2.0 Quiz
HLML Quiz
XML Quizzes
XML Quiz
XSL Quiz
XSLT Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XSL-FO Quiz
XML DOM Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
SOAP Quiz
WSDL Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizzes
JavaScript Quiz
VBScript Quiz
DHTML Quiz
HTML DOM Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizzes
ASP Quiz
PERL Quiz
SQL Quiz
ADO Quiz
CVS Quiz
Python Quiz
Apple Script Quiz
PL/SQL Quiz
SQL Server Quiz
PHP Quiz
.NET (dotnet) Quizzes
Microsoft.Net Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
ADO.NET Quiz
VB.NET Quiz
VC++ Quiz
Multimedia Quizzes
SVG Quiz
Flash Quiz
Media Quiz
SMIL Quiz
Photoshop Quiz
Gimp Quiz
Matlab Quiz
Gnuplot Programming Quiz
GIF Animation Quiz
Scientific Visualization Quiz
Graphics Quiz
Web Building Quizzes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Weblogic Quiz
SEO Quiz
Web Site Hosting Quiz
Domain Name Quiz
Java Quizzes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Eclipse Quiz
J2ME Quiz
JBOSS Quiz
Programming Langauges Quizzes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Cobol Quiz
Assembly Language Quiz
Mainframe Quiz
Forth Programming Quiz
Lisp Programming Quiz
Pascal Quiz
Delphi Quiz
Fortran Quiz
OOPs Quiz
Data Warehousing Quiz
CGI Programming Quiz
Emacs Quiz
Gnome Quiz
ILU Quiz
Soft Skills Quizzes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz
Database Quizzes
Oracle Quiz
MySQL Quiz
Operating System Quizzes
BSD Quiz
Symbian Quiz
Unix Quiz
Internet Quiz
IP-Masquerading Quiz
IPC Quiz
MIDI Quiz
Software Testing Quizzes
Testing Quiz
Firewalls Quiz
SAP Module Quizzes
ERP Quiz
ABAP Quiz
Business Warehousing Quiz
SAP Basis Quiz
Material Management Quiz
Sales & Distribution Quiz
Human Resource Quiz
Netweaver Quiz
Customer Relationship Management Quiz
Production and Planning Quiz
Networking Programming Quizzes
Corba Quiz
Networking Quiz
Microsoft Office Quizzes
Microsoft Word Quiz
Microsoft Outlook Quiz
Microsoft PowerPoint Quiz
Microsoft Publisher Quiz
Microsoft Excel Quiz
Microsoft Front Page Quiz
Microsoft InfoPath Quiz
Microsoft Access Quiz
Accounting Quizzes
Financial Accounting Quiz
Managerial Accounting Quiz
Testimonials | Contact Us | Link to Us | Site Map
Copyright ? 2008. Academic Tutorials.com. All rights reserved Privacy Policies | About Us
Our Portals : Academic Tutorials | Best eBooksworld | Beyond Stats | City Details | Interview Questions | Discussions World | Excellent Mobiles | Free Bangalore | Give Me The Code | Gog Logo | Indian Free Ads | Jobs Assist | New Interview Questions | One Stop FAQs | One Stop GATE | One Stop GRE | One Stop IAS | One Stop MBA | One Stop SAP | One Stop Testing | Webhosting in India | Dedicated Server in India | Sirf Dosti | Source Codes World | Tasty Food | Tech Archive | Testing Interview Questions | Tests World | The Galz | Top Masala | Vyom | Vyom eBooks | Vyom International | Vyom Links | Vyoms | Vyom World | Important Websites
Copyright ? 2003-2024 Vyom Technosoft Pvt. Ltd., All Rights Reserved.