diff --git a/README.md b/README.md
index 18315b5..13d5a19 100644
--- a/README.md
+++ b/README.md
@@ -149,4 +149,33 @@ Make sure your STL is low poly. The 3D example use a model with < 5000 triangles
## Converting Sprites and Images
The Utilities folder provides a convenient [SpriteEditor](https://htmlpreview.github.io/?https://github.com/bitluni/ESP32Lib/blob/master/Utilities/SpriteEditor.html) that you can use directly from the browser. No worries, your files are not uploaded.
The correct pixel format for VGA14Bit and VGA3Bit is R5G5B4A2 (that will be improved in future). You can import PNG files to use transparency.
-Each sprite has the origin in the center by default. You can modify it by changing the x/y values of the first point definition. Clicking on the image creates additional points that can be used for other purpouses like hit boxes etc.
\ No newline at end of file
+Each sprite has the origin in the center by default. You can modify it by changing the x/y values of the first point definition. Clicking on the image creates additional points that can be used for other purpouses like hit boxes etc.
+## Changing orentation
+Initiate a Gfxwrapper class
+```C++
+VGA3BitI vga;
+GfxWrapper
+```C++
+gfx.orientation = 90;
+```
+There are 6 types of oreintation that is supported:
+* object.orientation = 0 -> (default)actual orientation
+* object.orientation = 90 -> 90 degree clockwise rotation relative to actual
+* object.orientation = 180 -> 180 degree clockwise rotation relative to actual
+* object.orientation = 270 -> 270 degree clockwise rotation relative to actual
+* object.orientation = -1 -> flip horizontally
+* object.orientation = -2 -> flip vertically
+### Notes
+* Rotating the display causes your horizontal and vertical resolution to change. For example: if you have default resolution of 640 by 480 then rotating 90 degree clockwise will change your resolution to 480 by 640. So you have to keep it in mind while displaying rotated graphics. please refer to the [example](https://github.com/AsifKhan991/Customized-GFXwrapper-library-for-Bitluni-ESP32/blob/main/GFXwrapper_oreintation_example.ino) sketch to understand how it works.
+* It is possible to set individual rotation for individual graphics objects in the display. For this just simply set the desired orientation before displaying the graphics and then just revert to previous orientation. For exaample:
+```C++
+gfx.orientation = 270; //setting desired orientation before displaying
+gfx.setCursor(320 , 240);
+gfx.print("individual rotation"); //displaying sometihng (can be text or graphics)
+gfx.orientation = 0; // revert baack to original orientation
+```
+* Although it is not implemented, tweaking a bit in the library will enable rotating to any arbitrary angles (i.e: 15, 129, 287 etc). The functionality lies in the drawPixel() function of the Gfxwrapper class.
+### How the example sketch looks in display
+
diff --git a/examples/GFXwrapper_oreintation_example/GFXwrapper_oreintation_example.ino b/examples/GFXwrapper_oreintation_example/GFXwrapper_oreintation_example.ino
new file mode 100644
index 0000000..da22e7b
--- /dev/null
+++ b/examples/GFXwrapper_oreintation_example/GFXwrapper_oreintation_example.ino
@@ -0,0 +1,68 @@
+/*
+ * Date : 7/8/2022
+ * Author: Md. Asifuzzaman Khan
+ * Github: https://github.com/AsifKhan991/Customized-GFXwrapper-library-for-Bitluni-ESP32
+ *
+ * This example shows how the display orientation can be changed using Bitluni's ESP32 VGA library by
+ * the "object.orietnation" vairable of Gfxwrapper class.
+ *
+ * Tested on ESP32 DevKit-V1 & DevKitC-V4
+ *
+ * There are 4 modes total:
+ * object.orientation = 0 -> (default)actual orientation
+ * object.orientation = 90 -> 90 degree clockwise rotation relative to actual
+ * object.orientation = 180 -> 180 degree clockwise rotation relative to actual
+ * object.orientation = 270 -> 270 degree clockwise rotation relative to actual
+ * object.orientation = -1 -> flip horizontally
+ * object.orientation = -2 -> flip vertically
+ *
+ * Credit goes to bitluni for creating such an amazing library.
+ * Project page: https://github.com/bitluni/ESP32Lib
+ */
+#include
+#include
+#include
+
+const int redPin = 14;
+const int greenPin = 12;
+const int bluePin = 27;
+const int hsyncPin = 32;
+const int vsyncPin = 33;
+VGA3BitI vga;
+GfxWrapper gfx(vga, 640, 480);
+
+void setup() {
+ vga.init(vga.MODE640x480, redPin, greenPin, bluePin, hsyncPin, vsyncPin); // initiating in 640 by 480 resolution
+ gfx.setTextColor(0x0F00);
+ gfx.setFont(&FreeSansBold12pt7b);
+}
+
+void loop() {
+ gfx.orientation = 0; //Not necessary to declare the default orientation
+ gfx.setCursor(80 , 40);
+ gfx.print("Rotation example");
+ gfx.orientation = 90;
+ gfx.setCursor(80 , 40);
+ gfx.print("Rotation example");
+ gfx.orientation = 180;
+ gfx.setCursor(80 , 40);
+ gfx.print("Rotation example");
+ gfx.orientation = 270;
+ gfx.setCursor(80 , 40);
+ gfx.print("Rotation example");
+
+ gfx.orientation = 0;
+ gfx.setCursor(325 , 150);
+ gfx.print("Horizontal flip");
+ gfx.orientation = -1;
+ gfx.setCursor(325 , 150);
+ gfx.print("Horizontal flip");
+
+ gfx.orientation = 0;
+ gfx.setCursor(220 , 235);
+ gfx.print("Vertical flip");
+ gfx.orientation = -2;
+ gfx.setCursor(220 , 235);
+ gfx.print("Vertical flip");
+
+}
diff --git a/src/GfxWrapper.h b/src/GfxWrapper.h
index d14c208..bfe26e3 100644
--- a/src/GfxWrapper.h
+++ b/src/GfxWrapper.h
@@ -12,20 +12,37 @@
#pragma once
#include "Adafruit_GFX.h"
+
template
class GfxWrapper : public Adafruit_GFX
-{
+{
public:
+ int Xres,Yres,orientation=0;
Base &base;
typedef typename Base::Color Color;
- GfxWrapper(Base &vga, const int xres, const int yres)
+ GfxWrapper(Base &vga,const int xres, const int yres)
:base(vga),
Adafruit_GFX(xres, yres)
{
+ Xres=xres;
+ Yres=yres;
}
virtual void drawPixel(int16_t x, int16_t y, uint16_t color)
- {
- base.dot(x, y, base.RGBA((color >> 8) & 0b11111000, (color >> 3) & 0b11111100, (color << 3) & 0b11111000));
+ {
+ if(orientation==0){
+ base.dot(x, y, base.RGBA((color >> 8) & 0b11111000, (color >> 3) & 0b11111100, (color << 3) & 0b11111000)); // actual orientation
+ }else if(orientation==90){
+ base.dot(Xres-y, x, base.RGBA((color >> 8) & 0b11111000, (color >> 3) & 0b11111100, (color << 3) & 0b11111000)); // 90 degree c.c rotation from actual
+ }else if(orientation==180){
+ base.dot(Xres-x, Yres-y, base.RGBA((color >> 8) & 0b11111000, (color >> 3) & 0b11111100, (color << 3) & 0b11111000)); //180 degree c.c rotation from actual
+ }else if(orientation==270){
+ base.dot(y, Yres-x, base.RGBA((color >> 8) & 0b11111000, (color >> 3) & 0b11111100, (color << 3) & 0b11111000)); //270 degree c.c rotation from actual
+ }else if(orientation==-1){
+ base.dot(Xres-x, y, base.RGBA((color >> 8) & 0b11111000, (color >> 3) & 0b11111100, (color << 3) & 0b11111000)); //horizontal flip
+ }else if(orientation==-2){
+ base.dot(x, Yres-y, base.RGBA((color >> 8) & 0b11111000, (color >> 3) & 0b11111100, (color << 3) & 0b11111000)); //vertical flip
+ }
+
}
-};
\ No newline at end of file
+};