Author Topic: [C++][OpenGL] Sine Scroller  (Read 25404 times)

0 Members and 1 Guest are viewing this topic.

Offline lucastar

  • C= 64
  • **
  • Posts: 50
  • Karma: 5
    • View Profile
[C++][OpenGL] Sine Scroller
« on: May 10, 2013 »
Hi again!
I've managed to load and render true type fonts, my next step is making a sine scroller... I don't know where to start.
I understand the idea of picking a rectangle of a bitmap ("letter") and render it in another position, but can't this be done better with glVertex and rotation?
Thanks!

The image it's more or less what i want to do.

Offline Canopy

  • Atari ST
  • ***
  • Posts: 208
  • Karma: 20
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #1 on: May 10, 2013 »
not played with this part of GL yet.. but my first thoughts would be


render each letter to an FBO (puts them in GPU memory) then render each one to a quad per letter (texture mapped?,)
each quad can have translations/rotations applied to them in sequence?


btw this (GLRez) is probably a good place to look as the source is with it, and it has a waving sine scroller

http://pouet.net/prod.php?which=16327
« Last Edit: May 10, 2013 by Canopy »

Offline lucastar

  • C= 64
  • **
  • Posts: 50
  • Karma: 5
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #2 on: May 10, 2013 »
not played with this part of GL yet.. but my first thoughts would be


render each letter to an FBO (puts them in GPU memory) then render each one to a quad per letter (texture mapped?,)

That's what I'm doing right now. Drawing quads and binding the letter texture. I don't know how to make a FBO or write directly in GPU.

Offline Canopy

  • Atari ST
  • ***
  • Posts: 208
  • Karma: 20
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #3 on: May 10, 2013 »
you can probably get away without the FBO step , not sure about rotation though

make a linked list of your quads, then against each item in the list have a x position and y position, modify those every 1/16ths of a second or so, then update the final position and draw the character in the new positions?






Offline lucastar

  • C= 64
  • **
  • Posts: 50
  • Karma: 5
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #4 on: May 10, 2013 »
But it's not only drawing the letters in different positions, the "shape" of the characters must change too. It's difficult to explain it, but see the image I've attached before, the letters shape change depending on their position and orientation.

Offline Canopy

  • Atari ST
  • ***
  • Posts: 208
  • Karma: 20
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #5 on: May 10, 2013 »
in which case, i think the FBO approach must be it, unless theres another similar way (possibly a PBO)

you maintain a list of quads, you match each of those elements with a translation/rotation (along z too)), if you change something you recalc the matrix for the quad, 

the rotations will change the shape once the render happens

i'd start here

http://forum.openframeworks.cc/index.php?topic=9775.0;wap2

Offline lucastar

  • C= 64
  • **
  • Posts: 50
  • Karma: 5
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #6 on: May 10, 2013 »
I will take a look, thanks.

Offline Canopy

  • Atari ST
  • ***
  • Posts: 208
  • Karma: 20
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #7 on: May 10, 2013 »
having looked at the glrez source, its definitely use a texture quad and doing transformations similar to how i suggested above.
the main difference is its using immediate mode, whereas my mind tends to think in "modern gl" mode :(


this link goes to the inner loop where it does the translate/rotate for each letter for the waving sine text banner in the demo

https://github.com/chiptune/glrez/blob/master/glrez.cpp#L1243



Offline lucastar

  • C= 64
  • **
  • Posts: 50
  • Karma: 5
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #8 on: May 10, 2013 »
It will take me time to understand that code... i will try to include it in my code.

Offline Canopy

  • Atari ST
  • ***
  • Posts: 208
  • Karma: 20
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #9 on: May 10, 2013 »
found this screen shot having a quick poke around at the rest of the source showing the sin text stuff in the middle


Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: [C++][OpenGL] Sine Scroller
« Reply #10 on: May 12, 2013 »
I strongly suggest you to look on how to do it using GLSL fragment and vertex shader.
It's pretty easy using GLSL to make a sine scroller and it will be very useful when you advance in your gfx programming study.
Challenge Trophies Won:

Offline lucastar

  • C= 64
  • **
  • Posts: 50
  • Karma: 5
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #11 on: May 13, 2013 »
Ok, i did it canopy's way. The effect on the demo is good, but not exactly which i wanted. The position and z orientation change, but shape doesn't.
I will try to add the FBO stuff, and if it does not work, try the GLSL way.
Uploaded the executable file, i don't know if it works on another PC, please try  ;)

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #12 on: May 13, 2013 »
Works fine here lucastar, on Win7 x64 with a GTX 580 card.

Curious to see how it looks when scrolling across the screen  :)
raizor

Challenge Trophies Won:

Offline lucastar

  • C= 64
  • **
  • Posts: 50
  • Karma: 5
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #13 on: May 13, 2013 »
Works fine here lucastar, on Win7 x64 with a GTX 580 card.

Curious to see how it looks when scrolling across the screen  :)

thanks Raizor, i used your font classes to load the image and bind the texture correctly  ;).

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: [C++][OpenGL] Sine Scroller
« Reply #14 on: May 13, 2013 »
Uploaded the executable file, i don't know if it works on another PC, please try  ;)
Even works with wine (an emulator to run windows executables under linux), so it quite possibly runs everywhere :)
Challenge Trophies Won:

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #15 on: May 13, 2013 »
thanks Raizor, i used your font classes to load the image and bind the texture correctly  ;).

Great :)
raizor

Challenge Trophies Won:

Offline Canopy

  • Atari ST
  • ***
  • Posts: 208
  • Karma: 20
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #16 on: May 13, 2013 »
nice.. works on win7 x64 here as well with my radeon 6450 HD

Offline lucastar

  • C= 64
  • **
  • Posts: 50
  • Karma: 5
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #17 on: May 13, 2013 »
Thanks to all, I'm trying to emulate that movement... it's difficult, I'm thinking about using GLSL xD.
As soon as i get close, I'll upload the SC.

Offline lucastar

  • C= 64
  • **
  • Posts: 50
  • Karma: 5
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #18 on: May 14, 2013 »
Ok, i got a cute wave effect, but i can't get the character distorsion right.
Here is the example, for anyone who wants to try.
The method is _DrawChar on bmpFont.cpp class, and the z rotation seems to be working ok.
Sorry about the huge .rar size...

Offline Knurz

  • Atari ST
  • ***
  • Posts: 121
  • Karma: 25
    • View Profile
    • GitHub Repository
Re: [C++][OpenGL] Sine Scroller
« Reply #19 on: May 14, 2013 »
Ok, i got a cute wave effect, but i can't get the character distorsion right.
Here is the example, for anyone who wants to try.
The method is _DrawChar on bmpFont.cpp class, and the z rotation seems to be working ok.
Sorry about the huge .rar size...

I haven't looked at rez's code and yours but that's what I see in his glrez intro:
He is doing a full sine wave at the y-axis (normal sine-scroller effect) and is rotating on the z axis each char individually. As you can see in the text-passages each char is "waving" up (or down) till it reaches a limit, then he is doing a smaller z-rotation. Maybe he is simple triggering a function when the position of one char on the Y axis is reaching a value, and this function simple is rotating the char based on the "steps" the char has taken since the function has been triggered (that's how I would do it).

Maybe this is effects are obvious and I'm writing bullsh*t, but Rez is a master of design, and at this stage of his carreer  (when the glrez intro was written) with openGL the effects are more nice tricks (like his blending orgies in some intros) but he is designing his stuff in a really nice perfect way.

Brgds (and post your results  :) )
Remember what the dormouse said: Feed your head