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


Texture Generation


Previoushome Next






Texture Generation


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

The XOR Texture


Introduction


The XOR texture is a very easy to generate texture that looks fine. However, it's so overused that it's not a good choice to use in in a demo or intro release. It isn't useful for games either, unless you want some fancy floor tiles. What it's useful for, is for testing a texture mapper you just wrote, in case you want to quickly test out a pattern without having to load an image file or write more complex texture generation code.

This is an extremely small article, but the XOR Texture just couldn't be left out in a series of texture generation articles.
 

The XOR Texture


The XOR texture is simply generated by xor-ing the x and y coordinate of the current pixel. The '^' operator in C++ is the XOR operator.

 

int main(int argc, char *argv[]) 
{ 
    screen(256, 256, 0, "The XOR Texture"); 
   
    for(int x = 0; x < w; x++) 
    for(int y = 0; y < h; y++) 
    {    
         Uint8 c = x ^ y; 
         pset(x, y, ColorRGB(c, c, c)); 
    } 
   
    redraw(); 
    sleep(); 
    return 0; 
}

That's it, if you run it, you see the XOR texture:

The XOR Texture

There are 3 things you should keep in mind though:

1) The sizes of the texture should be a power of two, if they aren't, the texture doesn't look as good:



2) Color component values range from 0 to 255. The maximum color value generated by the XOR operation is the same as the dimensions of the texture if it's size is a power of two. So if the size of your XOR pattern is smaller than 256, for example only 64, it'll be too dark (image on the left). Multiply the color with 4 to make it bright again (image on the right):



3) On the other hand, if the size is larger than 256, for example 512, you have to make sure the color is limited to a maximum value of 256. You can either modulo divide it through 256, but then it isn't a real XOR pattern anymore. Better is to divide it through 2. In any case, using a XOR texture larger than 256x256 doesn't increase the quality because there aren't enough distinct color values, unless you're using a color mode that allows more bits per channel. But who'd want to generate a 1024x1024 XOR texture anyway.

The XOR operator takes the binary values of both integers, and does a binary XOR on every two corresponding bits. XOR or eXclusive OR returns 1 if both bits are different, and returns 0 if both bits are the same: "Bit a is 1 OR bit 2 is 1, but not both". In other words, it applies the following truth table to every two corresponding bits:

XOR
 
Bit_a
 
Bit_b
 
Result
 
0
 
0
 
0
 
0
 
1
 
1
 
1
 
0
 
1
 
1
 
1
 
0
 

This is done on every bit of the integer, creating the many possible resulting values.

For example, 5 XOR 13 = 8, because in binary 0101 XOR 1101 = 1000.

 

Colors


You can also try the XOR texture with different colors, by using different value for R, G and B. For example:

 

int main(int argc, char *argv[])
{
    screen(256, 256, 0, "The XOR Texture");
  
    ColorRGB color;
    
    for(int x = 0; x < w; x++)
    for(int y = 0; y < h; y++)
    {   
         Uint8 c = (x ^ y);
         color.r = 255 - c;
         color.g = c;
         color.b = c % 128;
         pset(x, y, color);
    }
      
    redraw();
    sleep();
    return 0;
}



You can even use the xor value as hue for the HSVtoRGB function...

 
int main(int argc, char *argv[])
{
    screen(256, 256, 0, "The XOR Texture");
  
    ColorRGB color; 
      
    for(int x = 0; x < w; x++)
    for(int y = 0; y < h; y++)
    {   
         Uint8 c = (x ^ y);
         color = HSVtoRGB(ColorHSV(c, 255, 255));
         pset(x, y, color);
    }
  
    redraw();
    sleep();
    return 0;
}



 

AND and OR


The AND and the OR operator also generate a similar texture.

The XOR operator returns 1 if both bits are different:

XOR
 
Bit_a
 
Bit_b
 
Result
 
0
 
0
 
0
 
0
 
1
 
1
 
1
 
0
 
1
 
1
 
1
 
0
 

The AND operator, only returns 1 if both bits are 1 (bit a AND bit b are true)

AND
 
Bit_a
 
Bit_b
 
Result
 
0
 
0
 
0
 
0
 
1
 
0
 
1
 
0
 
0
 
1
 
1
 
1
 

The OR operator returns 1 if any or both of the bits are 1 (bit a OR bit b is true)

OR
 
Bit_a
 
Bit_b
 
Result
 
0
 
0
 
0
 
0
 
1
 
1
 
1
 
0
 
1
 
1
 
1
 
1
 

The AND operator is denoted '&' in C++, and the OR operator '|', replace the '^' operator with those to use the new operators. Here's the result of XOR, AND and OR respectively:



It makes sense that the AND texture is darker, because it returns 1 only in a single case. The OR texture is brighter, because it returns 1 very often. The sum of the XOR texture and the AND texture is the OR texture.
 

Conclusion


It was shown how easy it is to create a XOR texture, which makes the XOR texture useful to test if a texture renderer is working. However, it's not suitable for applications such as art or games.

Here, the XOR pattern was used as a 3D texture (x ^ y ^ z) to test if a planet texture renderer was working correctly:


© 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: Texture Generation, 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.