Jump to content

  • Log In with Google      Sign In   
  • Create Account

ICUP

Member Since 18 Aug 2007
Offline Last Active Dec 30 2012 02:05 AM

Topics I've Started

GLSL & Matrix Math Help

29 December 2012 - 11:39 PM

I'm new to 3-D math so I'm not sure if I'm doing this correctly.

 

I currently have a GLfloat[ 36 ] pyramid set to the buffer, and that data is sent to an vec4 Vertex in the shader.

 


#version 400 core

layout( location = 0 ) in vec4 Vertex;
uniform mat4 Model;

void main()
{
    gl_Position = Model * Vertex;
}

 

I then setup a 4x4 matrix to rotate around the y-axis, and send that as a uniform to the "Model" variable in the shader.

 

glm::mat4 ModelR(
        cos( rStepAngle ), 0.f, -sin( rStepAngle ), 0.f,
        0.f, 1.f, 0.f, 0.f,
        sin( rStepAngle ), 0.f, cos( rStepAngle ), 0.f,
        0.f, 0.f, 0.f, 0.f
        );

GLint ModelLoc = glGetUniformLocation( programs.basicShader, "Model" );
glUniformMatrix4fv( ModelLoc, 1, GL_FALSE, glm::value_ptr( ModelR ) );

 

I'm getting nothing on my screen except the clear color. I think I may be misunderstanding something here. Vertex is going to be 3 components (technically 4, with 0 at the end), that gets multiplied by the Model rotation. How many times is the main() of the shader being run? My understanding of it was that main() is run until all 12 vertices of the pyramid are multiplied by the Model matrix. Is this correct?

 

There's probably something wrong with my math...


Virtual Resolution, Scaling, and Assets

26 November 2012 - 05:58 PM

I have several questions concerning resolution.

The first thing I'm wondering is, if I allow users of a game to change resolution, by how much do I scale the different sprites/logos/HUD? Is there some sort of formula to this?

Second, let's say I want my game to be crisp/clear in 1080p resolution. How do I create art assets for this resolution? Someone suggested to me that I open up adobe photoshop, create a new document that is 1080p in height. I find that strange, because why would you draw a small character sprite in such a huge window?

If I end up using a virtual resolution, at what point do I scale objects? It seems to me that if I'm drawing everything to a virtual 1280x1024 resolution, but when it is actually displayed on the user set resolution, let's say 800x600, the scaling would have to be done each and every call to a draw which is alot, and would slow things down immensely.

How to load a mesh in two or more windows?

24 January 2012 - 03:33 AM

Can meshes not be loaded once and drawn in two viewports? How can meshes be shown in two or more viewports? I'm able to get a mesh drawn in one window, but if it tries to draw in a second, I get this error:

"Both a vertex shader and pixel shader must be set on the device before any draw operations may be performed."

If I only draw in one viewport, it works fine and the meshes show up.

Frame Independence and Speed

18 August 2011 - 10:15 AM

I tried using the methods on lazyfoo's site for frame rate independence. One problem I'm having though is that my game is running at different speeds on different computers. The differences are drastic. For example, on a Core 2 Duo 2.4 ghz 2gb ram PC, the ball will move extremely fast, but the paddle moves slowly. On an Intel Centrino laptop running Win7 w/plenty of ram, the ball moves slowly, but the paddle moves fast. On older computers like a Pentium 4 2.4 ghz, 768 ram computer, the ball moves realllllllllyyyyyyy sllllooowwww. Yes, that slow.

What might be some reasons this is happening, and how can I fix it? I can only assume that the code I wrote that deals with frame rate independence is wrong. Here are the relevant parts of the code. (btw, it's a breakout clone).

Code to move the ball
bool Ball::MoveBall( Uint32 deltaTicks ) {
        .....
	
	// X-COORDINATE
	xOffset += cos( radians ) * ( ballVelocity / 1000.f ) * flipx;
	ballPosition.x = (Sint16)xOffset;

        .......

     	// Y-COORDINATE
	yOffset += sin( radians ) * ( ballVelocity / 1000.f ) * flipy;
	ballPosition.y = (Sint16)yOffset;

        .....
}

Code to move the paddle
void Paddle::Move( Uint32 deltaTicks ) {
	xOffset += xVel * ( deltaTicks / 1000.f );
	paddlePosition.x = (Sint16)xOffset;
}

Main loop
....
....

while ( SDL_PollEvent( &gEvent ) ) {
			handle.PaddleInput( &gEvent, stick );

			if ( gEvent.type == SDL_QUIT || gEvent.key.keysym.sym == SDLK_ESCAPE )
				quit = true;
		}
		stick.Move( time.GetTicks() );

		if ( ball.MoveBall( time.GetTicks() ) )
			wallSound.Play();

		if ( ball.CheckPaddleCollision( stick ) )
			paddleSound.Play();

		if ( ball.CheckBrickCollision( brickmap ) )
			brickSound.Play();

		if ( ball.IsBallDead() ) {
			ball.ResetBallPosition();
			stick.ResetPaddlePosition();
			stick.SetPaddleState( Paddle::RESET );
			launched = false;
			draw.GameObjects( lvl, brickmap, stick, ball );
		}

		draw.GameObjects( lvl, brickmap, stick, ball );
		time.Start();
		draw.Refresh();
.....
....

How do you statically link?

16 August 2011 - 09:37 PM

I'm done with a game I made and want it to be statically linked against SDL so that I don't have to distribute .dll files and VC++ redist. files.

What is the exact process I need to take?

I downloaded the SDL, SDL_image, SDL_mixer, and SDL_ttf source code, recompiling them as static libraries with /MT and /MTd. When using the newly compiled object library files, I get errors from SDL.lib and SDL_mixer.lib about unresolved externals (basically all the functions can't be found).

One thing I'm unsure about: when I compile the source, for some subsystems like SDL_mixer, there are subprojects, (something like) Timidity. Do those also need to be set to static library output? Do those code generation settings need to be set to /MT or/MTd? I did this, but didn't work.

PARTNERS