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

0 Members and 1 Guest are viewing this topic.

Offline lucastar

  • C= 64
  • **
  • Posts: 50
  • Karma: 5
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #20 on: May 14, 2013 »
I've been trying all day to use GLSL... i create a shader, i compile it, but i can't get anything showing on the screen.
I upload the code so if anyone has time to take a look and help me, i will be very grateful because i don't know what is wrong.
Thanks!

Offline Canopy

  • Atari ST
  • ***
  • Posts: 208
  • Karma: 20
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #21 on: May 14, 2013 »

i had a nightmare with shaders to begin with, especially since i wrote everything from scratch from windowing code right up.


best thing to do, is debug to see if they're failing.

if they aren't then its how you're using them, whether the uniforms/attributes have the right names and whether the shader is using it properly.

i've had a dig through the code and i think the main thing is.. there's only a vertex shader and no fragment shader. (3rd parameter to init) but not sure if its entirely relevent in your case








Offline lucastar

  • C= 64
  • **
  • Posts: 50
  • Karma: 5
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #22 on: May 14, 2013 »
I think there's no problem with that... but i didn't code the shader loader (i think Raizor is the author), so i'm not sure.

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #23 on: May 14, 2013 »
I'll have a look in a min lucastar. I stupidly uninstalled all versions of visual studio other than 2012 the other day, so you probably won't be able to open the project once I edit it (unless you have vs 2012?). I should be able to at least find the issue and point it out though. Fingers crossed :)
raizor

Challenge Trophies Won:

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #24 on: May 14, 2013 »
I should probably also ask, what are you expecting to see on screen?
raizor

Challenge Trophies Won:

Offline lucastar

  • C= 64
  • **
  • Posts: 50
  • Karma: 5
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #25 on: May 14, 2013 »
I'll have a look in a min lucastar. I stupidly uninstalled all versions of visual studio other than 2012 the other day, so you probably won't be able to open the project once I edit it (unless you have vs 2012?). I should be able to at least find the issue and point it out though. Fingers crossed :)

No, i don't have it, but i can get it on Thursday. If it is easier to you tell me.
Thanks!

Offline lucastar

  • C= 64
  • **
  • Posts: 50
  • Karma: 5
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #26 on: May 14, 2013 »
I should probably also ask, what are you expecting to see on screen?

In first place i tried http://zach.in.tu-clausthal.de/teaching/cg_literatur/glsl_tutorial/#flatten, but it didn't work.
Then i tried to create a shader that did nothing(I think):
Code: [Select]
void main()
{

gl_Position = ftransform();
}
It doesn't work either. When i say that don't work, i mean they are loaded and compiled correctly, but then nothing shows up.

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #27 on: May 14, 2013 »
Ok. Is there a particular reason for using a vertex shader? do you have something in mind? Just curious as I started playing around with fragment shaders to begin with.
raizor

Challenge Trophies Won:

Offline lucastar

  • C= 64
  • **
  • Posts: 50
  • Karma: 5
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #28 on: May 14, 2013 »
I thought the vertex shader was the one to use for vertex transformations, and to do the wave effect. Fragment shader is not more about color and texture stuff?

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #29 on: May 14, 2013 »
Sure, that makes perfect sense :)
raizor

Challenge Trophies Won:

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #30 on: May 14, 2013 »
Here you go lucastar.

The attached RAR file contains only the files I've changed. If you unpack that into the "framework64k" inside your project dir, you should be good to go.

It now draws a white quad (square) in the middle of the screen. I've changed the vertex shader to animate the quad according to the current time value. I've added some comments to the shader that hopefully make sense. Essentially, the shader does this.

1. Get the vertex position of the vertex (in local/object space).
2. Rotate the vertex according to the current time value.
3. Transform the vertex vertically according to sin(time), so that it bobs up and down.
4. Transform the vertex horizontally according to time, so it moves across the screen from right to left.
5. Transform the vertex into world space.

There was a bug in msys_glext.h causing oglUniform1f not to work. It was mapped to PFNGLUNIFORM1IPROC, rather than PFNGLUNIFORM1FPROC, basically pointing to the function that sets a uniform int value rather than float. I expect this was causing you some unknown headaches too. I've fixed it in the included file.

Hopefully there's enough here to get you going. You'll probably want to include a fragment shader at some point to do some fancy colouring or texture mapping for the characters.

raizor
raizor

Challenge Trophies Won:

Offline lucastar

  • C= 64
  • **
  • Posts: 50
  • Karma: 5
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #31 on: May 15, 2013 »
Thanks Raizor! this is very helpful!!
As soon as i get the results i want i will upload the code.

Thanks again!!!

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #32 on: May 15, 2013 »
You're most welcome lucastar, good luck :)
raizor

Challenge Trophies Won:

Offline lucastar

  • C= 64
  • **
  • Posts: 50
  • Karma: 5
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #33 on: May 19, 2013 »
I can't do better than this. No idea about how to change the character shape, only how to make a wave...
I have tried to do it with vertex shaders too, following the tutorial, but it only worked when drawing 3d objects.

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #34 on: May 19, 2013 »
I wouldn't worry too much about changing the character shape yet. Sure, you can do some really cool stuff like make it warp in the Z plane, so that it bulges towards and away from you, but leave that until later.

For now, I'd probably just try to angle the characters. How about changing the rotation angle by using the distance the character is above or below the baseline? For instance, if the character is positioned vertically in the middle of the screen, it would be rotated 0 degrees. As it moves up vertically, the rotation angle increases. Do the same for when the character moves down vertically (but use negative rotation below the center point), and I think it would look pretty good.

Don't give up yet, you're almost there :)
raizor

Challenge Trophies Won:

Offline lucastar

  • C= 64
  • **
  • Posts: 50
  • Karma: 5
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #35 on: May 19, 2013 »
Yes, that is what I'm trying to do right now.  ;)

Quote
I wouldn't worry too much about changing the character shape yet. Sure, you can do some really cool stuff like make it warp in the Z plane, so that it bulges towards and away from you, but leave that until later.

So... it must be very difficult am+ i right? ;D

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #36 on: May 19, 2013 »
Haha :) It's certainly achievable, but you're probably best leaving it until you have the angle and scrolling stuff sorted IMHO. Of course, it's totally up to you, but that's the order I'd approach it in.
raizor

Challenge Trophies Won:

Offline lucastar

  • C= 64
  • **
  • Posts: 50
  • Karma: 5
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #37 on: May 20, 2013 »
I think I've got it   :D
Not very nice, but i think this is the correct way.

Modify: of course nothing of changing char shape...
« Last Edit: May 20, 2013 by lucastar »

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #38 on: May 21, 2013 »
hey lucastar just had a proper go through your thread,

looks cool mate, and runs perfect on my dell laptop widows 7 geforce 650m core i7. im going too say you have the effect pretty much nailed as it looks as good as any old school pixel pushed sin scrolling stuff ( without the chars being cycled ). ive seen, k+
« Last Edit: May 21, 2013 by ninogenio »
Challenge Trophies Won:

Offline lucastar

  • C= 64
  • **
  • Posts: 50
  • Karma: 5
    • View Profile
Re: [C++][OpenGL] Sine Scroller
« Reply #39 on: May 21, 2013 »
Thanks ninogenio! Now i'm trying to do the char stuff...
If I make it, i will upload results + code.