Jump to content

  • Log In with Google      Sign In   
  • Create Account


PauliusM

Member Since 23 Jan 2012
Offline Last Active Apr 23 2014 01:53 AM

Topics I've Started

Drawing 2D shadows with "pure" SDL2

15 April 2014 - 06:35 AM

As the title say I want to draw 2d shadows only unsing sdl2 without openg, I have done it but the performence isnt the best,
I get like from 300fps+ to 90fps+ with 17 rectangles.

 

video:

Pc Spec:
Cpu i3-3110M
Gpu Nvidia 630M

Render everything in: 1280x720

 

when I get low fps My shadow drawing algorithm call 300+ drawing call to draw shadow for every object thats is on the screen;

to draw shadows I use triangles(still rectangle just the texture is triangle) and few rectangles pic:

xi7ayWi.png?1?5724

 

In the code I calculate the position from the mouse to the rectangle ant how much should the shadow go until it reaches the screen end,the calculation doesnt hit much in performence, but the drawing is just killing everything, I need somehow to lower the drawing calls.

 

Does anybody know any better way to draw without OpenGL?

 

Some tutorials that I saw draw the light itself, but I dont know how would I do it with out OpenGL for triangle drawing.

 

 

 

 

 

 

//EDIT:

Added source and executable (you can compile the code on android too)

 


Snake Free Android game!

22 March 2014 - 06:17 AM

Yesterday was a big day to me as I realeased my first simple game on Android market.

Its is really my first complete game,it was hard, I had to learn a lot of stuff that doesnt have many of tutorials on the internet, how to set up sdk and ndk.

This game was developed using 99% c/c++ SDL, the 1% is for creating a highscore file in app directory, had to use jni(which i still dont understad very well).

If removing the jni stuff the game works on Windows and linux, probably even on IOS.

The hardest part was the begining and the end, the reason why is because in the begining you dont know from where to start and in the end there is too much stuff, but you get used to it and everything becomes quite easy.

The main reason why I created the was to improve my developing skill and to understand game logic, how do they work.

Development took about 2 weeks a lot of brainstorming was done, and a lot of motivation was needed. My best friend during the work time was google and sdl wiki, I learned to coding wiki and its just an amazing info source. I worked on the game during the time every day, from like 20min up to whole day.

I hope you can test the game and leave feedback at google store thx.

TLDR: it was hard, but I did it.

 

 

You can download the game from here:

https://play.google.com/store/apps/details?id=org.Snake_.app


[C++/SDL/OpenGL] Wrong mouse information in specific area.

04 April 2012 - 10:29 AM

As the title says, I am getting wrong mouse information in specific area

Here is the picture in wich are I get wrong coordinates:

Posted Image

The code:

#include "SDL.h"
#include <SDL_opengl.h>
#include <GL/glu.h>
#include <sstream>
int SCREEN_WIDTH = 800;
int SCREEN_HEIGHT = 640;
const int SCREEN_BPP = 32;
const int FRAMES_PER_SECOND = 60;
SDL_Surface *surface;
SDL_Event event;

GLvoid ReSizeGLScene(GLsizei width, GLsizei height)
{
	 if (height==0)							  // Prevent A Divide By Zero By
	{
		height=1;						   // Making Height Equal One
	}
	glViewport( 0, 0, width, height );
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity( );
	gluPerspective( 45.0f, ( GLfloat )width / ( GLfloat )height, 0.1f, 100.0f );
	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity( );
}

int initGL( GLvoid )
{
	 glEnable(GL_TEXTURE_2D);	   // Enable Texture Mapping ( NEW )
	 glShadeModel(GL_SMOOTH);	   // Enable Smooth Shading
	 glClearColor(0.0f, 0.0f, 0.0f, 0.5f);	// Black Background
	 glClearDepth(1.0f);		 // Depth Buffer Setup
	 glEnable(GL_DEPTH_TEST);	   // Enables Depth Testing
	 glDepthFunc(GL_LEQUAL);		// The Type Of Depth Testing To Do
	 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
	return TRUE ;
}

void clean_up()
{
	//Quit SDL
	SDL_Quit();
}

void GLDRAW(GLvoid)
{
	 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	 glLoadIdentity();
	 glTranslatef(0.0f,0.0f,-10.0f);
	 glBegin(GL_QUADS);		 // Draw A Quad
	 	 glVertex3f(0.0f , 0.64f, 0.0f);	 // Top Left
	 	 glVertex3f(0.64f ,0.64f, 0.0f);	 // Top Right
	 	 glVertex3f(0.64f ,0.0f , 0.0f);	 // Bottom Right
		  glVertex3f(0.0f , 0.0f , 0.0f);	 // Bottom Left
	 glEnd();
}

int Timer()
{
	 int startTicks = 0;
	 startTicks = SDL_GetTicks();
	 return SDL_GetTicks() - startTicks;
}

int main( int argc, char *argv[] )
{
	//Quit flag
	bool quit = false;
	if( SDL_Init( SDL_INIT_EVERYTHING ) < 0 )
	{
		return false;
	}

	 if( SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER | SDL_OPENGL ) == NULL )
	{
		return false;
	}

	 initGL( );
	 ReSizeGLScene( SCREEN_WIDTH, SCREEN_HEIGHT );
	 int x = 0, y = 0;
	 float x3d,y3d,z3d;
	 //Wait for user exit
	 while( quit == false )
	 {
		//Start the frame timer
		//While there are events to handle
	   while( SDL_PollEvent( &event ) )
	   {
   	 	 if( event.type == SDL_MOUSEMOTION )
			 {
		 	 	 x = event.motion.x;
				  y = event.motion.y;
		 	 	 GLdouble model_view[16];
		 	 	 glGetDoublev(GL_MODELVIEW_MATRIX, model_view);
		 	 	 GLdouble projection[16];
		 	 	 glGetDoublev(GL_PROJECTION_MATRIX, projection);
		 	 	 GLint viewport[4];
		 	 	 glGetIntegerv(GL_VIEWPORT, viewport);
		 	 	 double dx; double dy; double dz;
		 	 	 GLfloat depth[2];
		 	 	 glReadPixels (x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, depth);
		 	 	 gluUnProject(x, y, depth[0], model_view, projection, viewport, &dx, &dy, &dz);
		 	 	 x3d = float(dx);
		 	 	 y3d = float(dy);
		 	 	 z3d = float(dz);
   	   }

   	   if( event.type == SDL_QUIT )
   	   {
				quit = true;
		  }
}
	 	   //Clear the screen
	 	   glClear( GL_COLOR_BUFFER_BIT );
	 	   //Show the square
	 	   GLDRAW();
			//Update screen
	   	 SDL_GL_SwapBuffers();
	   	 std::stringstream time;
	   	 time << "X: " << x3d << " Y: " << y3d;
	   	 SDL_WM_SetCaption( time.str().c_str(), NULL );
	 	 }
//Clean up
clean_up();
return 0;
}

[C++/OpenGL] Can't load multyple textures.

26 March 2012 - 10:57 AM

I am trying to create multyple texture with soil, but when I compile I only see white cube without textures.
I think glGenTextures is causing the problem, because without it textures load.

Can I use SOIL and glGentextures?

int LoadGLTextures()								    // Load Bitmaps And Convert To Textures
{
    /* load an image file directly as a new OpenGL texture */
    texture[0] = SOIL_load_OGL_texture
	    (
	    "lol.bmp",
	    SOIL_LOAD_AUTO,
	    SOIL_CREATE_NEW_ID,
	    SOIL_FLAG_INVERT_Y
	    );
    if(texture[0] == 0)
	    return false;
glGenTextures(3,&texture[0]);
// Create Nearest Filtered Texture
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); // ( NEW )
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); // ( NEW )
    // Typical Texture Generation Using Data From The Bitmap
    glBindTexture(GL_TEXTURE_2D, texture[1]);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
// Create MipMapped Texture
glBindTexture(GL_TEXTURE_2D, texture[2]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); // ( NEW )
    return true;									    // Return Success
}

SOIL linking problem [SOLVED]

26 March 2012 - 06:18 AM

I get this error when I link SOIL.lib

1>------ Build started: Project: OpenGL, Configuration: Debug Win32 ------
1>SOIL.lib(stb_image_aug.o) : error LNK2019: unresolved external symbol __alloca referenced in function _stbi_zlib_decode_noheader_buffer
1>SOIL.lib(image_helper.o) : error LNK2019: unresolved external symbol _sqrtf referenced in function _RGBE_to_RGBdivA2
1>C:\Users\Pc\Documents\Visual Studio 2010\Projects\Project\Debug\OpenGL.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


SOLVED:

Needed to rebuild the lib.

Used the vc8 project.

PARTNERS