parallax techniques?

I've been trying to find a good c++ tutorial on Parallax techniques but have been unable to locate anything particular helpful, I was just wondering if anyone knew some where were I could find some of tutorials or had some sort of sample code to give me an idea of how to incorporate it into c++
1) split your display into "layers"
2) assign each layer a scale (ie: 2.0 would scroll twice as fast, 0.5 would scroll half as fast)
3) draw each layer separately
4) When drawing a layer, multiply the current overall scroll by the layer's 'scale'
5) enjoy your new, fancy, paralax scrolling.


EDIT:

You can get even fancier and have layers "auto scroll" by giving each layer a scroll offset and an autoscroll rate. Just add the autoscroll rate to the offset every update, then draw at (main_scroll + scroll_offset) * scale.

Easy peasy.
Last edited on
Am I on the right track with this train of thought?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
         m_pSprite = new Sprite( "SplashScreen.JPG", "BackGround" );
	m_pSprite->Draw( 0, 0, 1024, 768, m_SplashImage); 

	static double someXOffset = 0.0;
	someXOffset += 0.1;
	if(someXOffset > 1000)  someXOffset -= 1000;

	glPushMatrix();
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glBindTexture(GL_TEXTURE_2D, m_SplashImage );
        glPushMatrix();
        
            glBegin(GL_QUADS);
                
                glTexCoord2f(0,0); glVertex2f(0,768);
                glTexCoord2f(1,0); glVertex2f(1024,768);
                glTexCoord2f(1,1); glVertex2f(1024,0);
                glTexCoord2f(0,1); glVertex2f(0,0);             
            glEnd();
         
        glPopMatrix();
        glDisable(GL_BLEND);
    glPopMatrix();


To me it looks like you are drawing the same image twice, so that doesn't seem right to me.

Also, any particular reason why you're mixing direct OpenGL calls with SFML sprite drawing calls? IIRC SFML will muck up the OpenGL state... so if you're going to do this, you will need to surround your OpenGL code with some SFML state save/restoring code. I forget exactly how to do it, as it's been a while.

Also you are pushing/popping the matrixes, but not modifying them....
Ah the first one news it and tells it were to find the file and what type it is
second one calls the draw code

Yeah i have noticed some of my stuff has been screwed with since this code..i;m working in a group assignment and one of my team mates made a sprite and texture class were i get my m_psprite from but he told me i could this GL stuff with it >.< i guess he was wrong =D
Ha I accidently removed my modifying code sigh

Ill google around how to save The sfml state stuff


Thanks again
Topic archived. No new replies allowed.