• Welcome to Dark Bit Factory & Gravity.
 

[C++][OpenGL] Sine Scroller

Started by lucastar, May 10, 2013

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

lucastar

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!

Canopy


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








lucastar

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.

Raizor

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:

Raizor

I should probably also ask, what are you expecting to see on screen?
raizor

Challenge Trophies Won:

lucastar

Quote from: Raizor 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!

lucastar

Quote from: Raizor 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):

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.

Raizor

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:

lucastar

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?

Raizor

Sure, that makes perfect sense :)
raizor

Challenge Trophies Won:

Raizor

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:

lucastar

Thanks Raizor! this is very helpful!!
As soon as i get the results i want i will upload the code.

Thanks again!!!

Raizor

You're most welcome lucastar, good luck :)
raizor

Challenge Trophies Won:

lucastar

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.

Raizor

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:

lucastar

Yes, that is what I'm trying to do right now.  ;)

QuoteI 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

Raizor

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:

lucastar

#37
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...

ninogenio

#38
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+
Challenge Trophies Won:

lucastar

Thanks ninogenio! Now i'm trying to do the char stuff...
If I make it, i will upload results + code.