Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411283 Posts in 69325 Topics- by 58380 Members - Latest Member: bob1029

March 29, 2024, 06:38:46 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)SDL camera?
Pages: [1]
Print
Author Topic: SDL camera?  (Read 4149 times)
IndieEmma
Level 2
**


View Profile
« on: August 24, 2012, 11:12:45 AM »

Hi!
I'm trying to make a camera for my game but I can't a good tutorial, I've googled and checked source code but I do just not understand it.
Can some one explain how I would make it? Can you tell me what the code would look like, or show me a good tutorial?

Thanks!
Logged
zacaj
Level 3
***


void main()


View Profile WWW
« Reply #1 on: August 24, 2012, 11:15:44 AM »

You mean so you can scroll around a level larger than the screen?
Logged

My twitter: @zacaj_

Quote from: mcc
Well let's just take a look at this "getting started" page and see--
Quote
Download and install cmake
Noooooooo
Polly
Level 6
*



View Profile
« Reply #2 on: August 24, 2012, 11:42:23 AM »

Assuming you're using OpenGL ( version < 3.3 ) along with SDL and your game is 2D, simply load the following matrix into GL_MODELVIEW before you render your objects.

float matrix[16] = {1,0,0,0,0,1,0,0,0,0,1,0,-camera.position.x,-camera.position.y,0,1};
Logged
IndieEmma
Level 2
**


View Profile
« Reply #3 on: August 24, 2012, 12:24:21 PM »

Assuming you're using OpenGL ( version < 3.3 ) along with SDL and your game is 2D, simply load the following matrix into GL_MODELVIEW before you render your objects.

float matrix[16] = {1,0,0,0,0,1,0,0,0,0,1,0,-camera.position.x,-camera.position.y,0,1};


I'm not using OpenGL
Logged
IndieEmma
Level 2
**


View Profile
« Reply #4 on: August 24, 2012, 12:25:53 PM »

You mean so you can scroll around a level larger than the screen?


Yes
Logged
Polly
Level 6
*



View Profile
« Reply #5 on: August 24, 2012, 12:32:07 PM »

I'm not using OpenGL

In that case it's probably easiest to render your objects at "object.position - camera.position". Obviously for parallax you'll need to take the depth in consideration as well .. but you might not need this Smiley

Any particular reason you don't / can't use hardware acceleration?
Logged
rivon
Level 10
*****



View Profile
« Reply #6 on: August 24, 2012, 02:06:27 PM »

Just use one SDL_Rect with x and y representing the position of the top-left corner. Then, when drawing stuff, their position on screen will be:
x = object.x - camera.x
y = object.y - camera.y
Logged
Hambone
Level 1
*


follow on the twitter @The_Hambone1988


View Profile WWW
« Reply #7 on: March 02, 2015, 11:36:36 PM »

DELETED
« Last Edit: March 03, 2015, 12:08:29 AM by Hambone » Logged

Wannabe indie game developer
Layl
Level 3
***

professional jerkface


View Profile WWW
« Reply #8 on: March 03, 2015, 05:11:02 AM »

Here's a little reference camera implementation.

https://github.com/LaylConway/JellyEmpire/blob/master/JellyEmpire/Camera.cpp
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic