[LibGDX]How to create gradient color

hi! I have another question ;D (maybe too mach in this days XD) i want to create a gradient background like this :

http://www.mypictales.com/backgrounds/content/4674/thumb2.jpg

my question is : How to do this in libgdx? I nedd a texture or i can avoid? I have googoled but i don’t know what to serach because i’m new in libgdx and i don’t know what to search exactly.
Thanx in advice and have a good day :smiley:

given that you don’t know that much about OpenGL, I would say the easiest way for you to achieve this is with a simple texture.

I will give you three possible implementation ideas ordered from easy to “hard”

  • Just create a gradient texture of the size you need in your prefered image application, then use the standard libgdx sprite batcher
  • create an Image in your app of the size 1x2 with the two colors you like to have a gradient with. Upload this image as a texture and set the filtering option to linear. then use it as before, this approach gives you the nice benefit to work perfect with every background size
  • If you know a bit OpenGL you could just create an Quad with the Color-Attribute set to the colors you want and let OpenGL interpolate them for you.

first of all thanks for the great answer! ;D
I really don’t know nothing about opengl but i’m interessed in it, can you suggest me some tutorial or other? i want to implement the 3th way, there is some explaination about it?

That one is quite usefull: https://github.com/mattdesl/lwjgl-basics/wiki/Shaders

Although I would encourage to learn the modern OpenGL way. I think a simple glBegin, glEnd would be enough for this simple gradient

The OpenGL code to draw a simple Quad should be something like this.


glBegin(GL_Quads);
//bottom
glColor3f(0.3f, 0f, 0f); //dark red
glVertex2f(-1, -1); //left bottom of screen
glVertex2f(1, -1);  //right bottom of screen
//top
glColor3f(1f, 0f, 0f); //full red
glVertex2f(-1, 1); //left top of screen
glVertex2f(1, 1);  //right top of screen

glEnd();

Sorry but i don’t know were i have to put this code ??? i’m so noob :’(

A full screen quad with different colored vertices should work too.