Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Wooh

Member Since 19 Dec 2008
Offline Last Active Yesterday, 08:32 AM

#5226011 how to crop on SDL 1.2

Posted by Wooh on 28 April 2015 - 01:47 AM

The function you need to understand is the SDL_BlitSurface function.
int SDL_BlitSurface(SDL_Surface* src, SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect);
src (first argument) is the SDL_Surface that you want to draw on to some other surface.
srcrect (second argument) is the rectangle that you want to cut out of src surface.
dst (third argument) is the SDL_Surface that you want to draw the src surface on.
srcrect (third argument) will decide where on the dst it will draw.

// The surface that we want to draw
SDL_Surface* src = SDL_LoadBMP("img.bmp");

// The area that we want to draw from img.bmp.
SDL_Rect srcrect; // The area is ...
srcrect.w = 100;  // ... 100x100 pixels ...
srcrect.h = 100;  //
srcrect.x = 0;    // ... with the top left corner located at position (0,50)
srcrect.y = 50;   //

// The surface that we want draw on.
SDL_Surface* dst = SDL_GetVideoSurface(); // The screen surface

// The position on the screen where the top left corner of the cropped image will be drawn.
SDL_Rect dstrect;
dstrect.x = 10;
dstrect.y = 20;
// w and h will not be used by SDL_BlitSurface.

SDL_BlitSurface(src, &srcrect, dst, &dstrect);



#5223901 FastCall Is Alll

Posted by Wooh on 17 April 2015 - 03:14 AM

The true horror though is that a lot of these already *have* alternative tokens:

http://en.cppreference.com/w/cpp/language/operator_alternative


I tried some of these alternitives but it failed to compile (VS9)
You have to disable microsofts language extensions...
https://msdn.microsoft.com/en-us/library/34h23df8.aspx#sectionToggle9
https://msdn.microsoft.com/en-us/library/0k0w269d.aspx


#5223349 Template or Macro

Posted by Wooh on 15 April 2015 - 01:19 AM

I think you should prefer templates unless you have a good reason not to.

If you pass an array to SAFE_DELETE it will still compile, but using templates you can force this to give you an error.

int arr[5];
SAFE_DELETE(arr);



#5220697 please help with SDL

Posted by Wooh on 01 April 2015 - 08:36 AM

Make sure you don't have any circular include dependencies.

SDLGameObject.h includes Game.h, so if Game.h includes Player.h (or Enemy.h) it will fail to work because Player.h need SDLGameObject but it has not yet been defined and the #pragma once prevents SDLGameObject.h from being included again.


#5216580 Best way to store user settings?

Posted by Wooh on 15 March 2015 - 02:01 AM

If the user is supposed to be able to edit the file manually it should be as simple as possible.

setting1=value1
setting2=value2
...

Otherwise it doesn't matter.


#5216350 SDL2_gfx texturedPolygon function question

Posted by Wooh on 13 March 2015 - 04:52 PM

Ignore what I just said. I was wrong. The shape made up of vx and vy cuts out a piece of the texture but what part depends on texture_dx and texture_dy.


#5212309 Is buying assets cheating?

Posted by Wooh on 22 February 2015 - 01:52 PM

If you see games as art (like a painting or a piece of music) I say it has higher value if you do it yourself. Only you can say if it's cheating because only you know what you want to do.


#5211639 How to disable vsync in SDL 2?

Posted by Wooh on 19 February 2015 - 03:12 AM

As I understand the docs you can also pass the SDL_RENDERER_PRESENTVSYNC flag when creating the renderer.

https://wiki.libsdl.org/SDL_CreateRenderer


#5208635 Why not chord tones?

Posted by Wooh on 04 February 2015 - 09:40 AM

In my quest to learn composing simple game music I thought I should study some old Mario songs because the simplicity of never having more than 3 notes at the same time. The Starman Theme starts with C, D and F. I thought this was a bit strange because these does not make up triad with notes a third apart.

To me it would make more sense if it used B, D and F because then they would be a chord consisting of a root, a third and a fifth. When I think about it I realize B, D and F would make up a B diminished chord so that would probably not sound very good but I don't understand how to think when using notes that are not part of a traditional chord. Why did they do it the way they did? Is there any "rules" to follow?


#5203067 Game event loop using ncurses library

Posted by Wooh on 09 January 2015 - 06:21 AM

The timeout function can be used to set how long getch will wait for input. timeout(0) will make getch() return immediately, and if there was no input the return value is ERR.


#5202266 I don't understand beats in music

Posted by Wooh on 06 January 2015 - 10:20 AM

I'm trying to learn music theory but I have problems understanding beats. I understand that the time signature decides how many beats there are in a bar and that some of these beats are stronger and some are weaker but I don't get what that means in practice.

Is the beat just something that is there to help the composer structure the music? Like for instance placing long notes on strong beats...

Or is it something that the instrument players should think about? Should a piano player hit the key with more force or with a different timing when playing a note that starts on a beat?


#5195133 SDL_WINDOWEVENT_EXPOSED not occurring

Posted by Wooh on 28 November 2014 - 03:33 AM

SDL_WINDOWEVENT_EXPOSED is just for when the graphics has to be redrawn. I'm not sure exactly when this happens but it probably depends on a lot of things. If the renderer is not hardware accelerated I suspect you never get this event.

If you want the graphics to update you should call the render function from somewhere else in the code. If you always update the whole screen very often you can probably ignore SDL_WINDOWEVENT_EXPOSED.


#5168877 This singleton keeps crashing.

Posted by Wooh on 24 July 2014 - 09:03 AM

<stdint.h> is part of the C standard library, not the C++ standard library. While most compilers allow you to include their C includes from C++, they are not required to do so (nor do they even have to have C includes somewhere to be standard compliant).


This is what the C++11 standard (Appendix D.5) says about it.
 

For compatibility with the C standard library and the C Unicode TR, the C++ standard library provides the 25 C headers, as shown in Table 154.

Table 154 - C headers
<assert.h><inttypes.h><signal.h><stdio.h><wchar.h>
<complex.h><iso646.h><stdalign.h><stdlib.h><wctype.h>
<ctype.h><limits.h><stdarg.h><string.h>
<errno.h><locale.h><stdbool.h><tgmath.h>
<fenv.h><math.h><stddef.h><time.h>
<float.h><setjmp.h><stdint.h><uchar.h>




#5165075 how to use or ||

Posted by Wooh on 06 July 2014 - 11:20 AM

Do you run this code repeatedly while the sound is playing?


#5164349 iterator output not in sync

Posted by Wooh on 02 July 2014 - 10:22 AM

Not sure if you missed my reply or maybe I was not clear.

Each time you call next() you will get a different element. In your code you are printing the x of the first element, the y of the second element and the z of the third element. In the next iteration you print the x of the fourth element, the y of the fifth element and the z of the sixth element. And so on.

To print the x, y and z of the same element you should only call next() once in each iteration.

while (vecIterator.hasNext()) {
	vector3D v = vecIterator.next();
	System.out.println("iterator list output " + v.x + " " + v.y  + " " + v.z);
}





PARTNERS