Game Engines: A Quick Peek

Game Engines are the core libraries which is used as the architecture to develop the game. It cuts down the pressure on development teams as all the complex coding is already written in the engine. The core functions that Game Engine provides are rendering(2d or 3d), physics engine or collision detection, sound, scripting, artificial intelligence. They provide all the core functionalities needed to develop a game while reducing the costs, complexities and time.

There are libraries that are developed to provide only one specific functions, called Middleware. Like Havok is a middleware which offers developers the foundation for creating realistic physics simulation.

Developers  license the engines like id tech, unreal to develop their titles. Some developers use their in-house proprietry engines created by themselves for their own titles. And their are also some free open source engines out there like OGRE, JMonkeyEngine.

Now i’ll discuss about some very well known Game Engines, Middleware And Engines used in making next-gen games.

Unreal Engine:

Unreal is a game engine developed by Epic Games. The games made by this engine are Gears of War franchise, Bioshock, splintercell, MassEffect and many other. This Engine has won the Game Developer’s Front Line awards in engine category for three consecutive awards. This Engine is Game Developer’s Front Line Awards 2008 Hall Of Fame winner. You can read Why Unreal Engine was the Hall Of Fame Winner.

gears2vid01

Gears of War 2 made with Unreal engine

Havok

Havok is a physics engine developed by Havok. Havok offers developers the foundation for creating realistic physics simulation through efficient and optimized calculation. The Titles that used Havok engine are Crackdown, Assassin’s creed, F.E.A.R 2:Project Origin, Fallout 3, Halo 3 and many more. Havok won the Game Developer’s Front Line Awards 2008 in Middleware category. Read why Havok won the award ?.

company-of-heroes

Company of Heroes using Havok engine

cryEngine

Developed by CryTek is the force behind those killer graphics of crysis. They set a new standard for visuals. CryTek released a GDC demonstration movie for their latest all-in-one game development solution using cryEngine 3, premiered at GDC 2009 in san fransisco. cryEngine 3 is the first development platform for Xbox 360, Playstation 3, MMO, DX9/DX10 and includes cryEngine 3 Sandbox level editor and “What you see is what you play” tool designed for professional developers. 3 comes with significant feartures for consoles and next-gen game development.

crysis

crysis made with cryEngine

R.A.G.E (Rockstar Advanced Game Engine)

R.A.G.E is a game engine developed by a team called “Rage Technology Group” at Rockstar san diego. Rockstar has integrated a few third party middleware like euphoria character animation engine and Bullet physics engine. GTA4 was developed with this cool engine. Rockstar are working on a game Red Dead Redemption which uses R.A.G.E engine. The trailer of Read dead Redemption looks really cool with realistic horses, towns, prairies….with ralistic weather. R.A.G.E engine provides functionalities to handle realistic weather effects, complex A.I, large worlds..etc

Check this video of Red Dead Redemption, its jusshows you what R.A.G.E is capable of doing.

gta4

Grand Theft Auto 4 made with R.A.G.E engine

Naughty Dog Game Engine

This Engine is developed by Naughty Dog. This year naughty Dog showcased their upcoming title Uncharted 2 at sony playstation 3 conference, E3 2009 . I was awestruck by watching the trailer and demo. I had never seen such a cinematic game(demo) before, graphics looked so awesome and cool. Naughty Dog with Uncharted 2 really showed the world what Ps3 is capable to do. So i would say Naughty Dog maxed out the Ps3 with Uncharted 2. The demo showcased realistic environments, smooth animation-interaction, cinematic feel with cinematic camera work :D …seamless transition between cinematic and gameplay.

So there are other engines also that i haven’t mentioned like Valve’s Source engine which gave titles like half-life franchise, left 4 dead, Infinity Ward’s IW engine which gave Call Of Duty franchise(not all sequels), Ubisoft’s Anvil engine which was used for Assassin’s creed….and many more engines. I have just  quickly looked at just some good engines that took my interest. This post is not on best engines but tells about good engines.

Gracias.


Posted in consoles, developer, games | Tagged | Leave a comment

My Experience with Xbox 360 and PS3

consoles

Hola everyone.

I have seen many gamers on forums discussing on the debate: Xbox 360 vs PS3. Half section of gamers says Xbox 360 is best and other half says PS3 is superior and debate goes on and on. Many newbies gets confused and they do not know which consoles to buy.

I don’t have any of the consoles at my home. I have 2 friends, one of whom has got xbox 360 and other has got both 360 and ps3. So i just visit their places frequently to play games and experience the gaming on both consoles. So here i am going to share my experience with both consoles.

Before sharing my experience, i want the readers to know that this post is not on the debate: Xbox 360 vs PS3. This is post reflects just my experience so don’t make any issues with it. :D

So first i will give u a glance on inside the two consoles that run these amazing game titles:

PS3:

a) Seven Single Threaded Processors (3.2 GHz)

b) One Multi-Threaded cell processor (3.2 GHz)

c) Nvidia ‘RSX’ custom made graphic processor

Xbox 360:

a) Triple-Dual threaded core Xenon Processor (3.2 GHz)

b) ATI ‘Xenon’ GPU

That was the inside configuration of both systems.

I am not a fan of either consoles. I am a gamer and i love to play and enjoy games.

Many gamer says that they have played specific game titles on both consoles and they found Xbox 360 version better and superior than PS3’s for example: GTA 4. But i would like to mention that almost all multi-platform titles like GTA 4, Assasin’s creed..etc are a 360 to PS3 port, so these games may not look better on PS3 and look good in Xbox 360. Like GTA 4 is a 360 to PS3 port, so developers had to cut some corners in order to ship the title on market in time. So i would say if time and money was there then the games would have been absolutely identical.

Gears Of War was an amazing title which is a 360 exclusive title. I am a big big fan of gears of war franchise and i still play it with my friends on split-screen mode on his xbox system and i never get bored. But but i and ofcourse you will notice that the game was short because xbox 360 only had dual layer dvd to work with, whereas PS3 has more disc space to work with to make bigger and better games. When KillZone 2 came out, it had an amazing graphics and i noticed that PS3 totally outperformed 360. Uncharted was also amazing cinematic game. Killzone 2 is one of the best fps games that i have played. :D

gear_uncharted

I love Xbox live. The interface is excellent and interaction between player is damn awesome and feature like achievements is also cool. I liked Xbox live more the way than PSN. In PSN i cannont send message to my friend from within the game. I didn’t get the facility of voice chatting on PSN. On Xbox live i can reach my friends right away in a single button press, send them voice/text message and invite my friend to the server where i am playing. Xbox live is just very very cool. But PSN is free for most part and for Xbox live u have to subscribe dollars $$$ :D But i am really cool with Xbox live, its just very cool than PSN. :D

xbox_psn

Putting Games on side for the moment and talking about movies than thumbs UP to PS3. PS3 is undoubtely the superior movie player with its integrated Blu-Ray technology. It has also got amazing sound quality. So i would say here Ps3 is far more better than Xbox 360.

blu-ray-logo-400

Xbox 360 makes a annoying background sound which really annoys me while watching the movie. PS3 is quiet during the movie on.

One thing that my friend and i like is Xbox live arcade that provides variety of arcade games than PSN provides.

In past Xbox 360 had a good line-up of exclusive games than Ps3 had. In 2007 Xbox had exclusive hit titles like Halo 3, BioShock and Mass Effect, whereas PS3 had titles like Uncharted, ratchet and clank future:tools of destruction. Many gamers said that PS3 didn’t have good varied exclusive titles. But 2008 was the PS3’s years as they had the best game line up with titles like Metal Gear Solid 4, Resistance 2 and Litle Big Planet wheras 360 had a nice titles like Gears Of War 2. So varied of good games is no longer an issues for PS3 as it was in past.

Well this was my experience till now, but there is more to experience. There is so much tight competition between the consoles. Each console has their advantages and disadvantages. I enjoy both system.

Gracias.


Posted in consoles | Tagged , | Leave a comment

List Of Good OpenGL and (ES) Books

These are the list of some popular books on OpenGl and (ES) preffered by many.

OpenGl SuperBible Fourth Edition

It begins by illuminating the core techniques of “classic” opengl programming, from drawing in space to geometric transformations, from lighting to texture mapping. The authors covers newer OpenGL capabilities, including OpenGL 2.1’s powerful programmable pipeline, vertex and fragment shaders, and advanced buffers. They also present thorough, up-to-date inroduction to opengl implementation on openl platforms, including windows,mac,linux and embedded systems.
Cove
rage includes

·         An entirely new chapter on OpenGL ES programming for handhelds

·         Completely rewritten chapters on OpenGL for Mac OS X and GNU/Linux

·         Up-to-the-minute coverage of OpenGL on Windows Vista

·         New material on floating-point color buffers and off-screen rendering

·         In-depth introductions to 3D modeling and object composition

·         Expert techniques for utilizing OpenGL’s programmable shading language

·         Thorough coverage of curves, surfaces, interactive graphics, textures, shadows, and much more

·         A fully updated API reference, and an all-new section of full-color images

superbible

The OpenGl Programming Guide: The Official Guide to Learning OpenGl Version 2.1

The OpenGL® Programming Guide, Sixth Edition, provides definitive and comprehensive information on OpenGL and the OpenGL Utility Library. The previous edition covered OpenGL through Version 2.0. This sixth edition of the best-selling “red book” describes the latest features of OpenGL Version 2.1. You will find clear explanations of OpenGL functionality and many basic computer graphics techniques, such as building and rendering 3D models; interactively viewing objects from different perspective points; and using shading, lighting, and texturing effects for greater realism. In addition, this book provides in-depth coverage of advanced techniques, including texture mapping, antialiasing, fog and atmospheric effects, NURBS, image processing, and more. The text also explores other key topics such as enhancing performance, OpenGL extensions, and cross-platform techniques.

This sixth edition has been updated to include the newest features of OpenGL Version 2.1, including:

  • Using server-side pixel buffer objects for fast pixel rectangle download and retrieval
  • Discussion of the sRGB texture format
  • Expanded discussion of the OpenGL Shading Language

This edition continues the discussion of the OpenGL Shading Language (GLSL) and explains the mechanics of using this language to create complex graphics effects and boost the computational power of OpenGL.

The OpenGL Technical Library provides tutorial and reference books for OpenGL. The Library enables programmers to gain a practical understanding of OpenGL and shows them how to unlock its full potential. Originally developed by SGI, the Library continues to evolve under the auspices of the OpenGL Architecture Review Board (ARB) Steering Group (now part of the Khronos Group), an industry consortium responsible for guiding the evolution of OpenGL and related technologies.

redbook

OpenGL Shading Language 2nd Edition

OpenGL® Shading Language, Second Edition, includes updated descriptions for the language and all the GLSL entry points added to OpenGL 2.0; new chapters that discuss lighting, shadows, and surface characteristics; and an under-the-hood look at the implementation of RealWorldz, the most ambitious GLSL application to date. The second edition also features 18 extensive new examples of shaders and their underlying algorithms, including

  • Image-based lighting

  • Lighting with spherical harmonics

  • Ambient occlusion

  • Shadow mapping

  • Volume shadows using deferred lighting

  • Ward’s BRDF model

The color plate section illustrates the power and sophistication of the OpenGL Shading Language. The API Function Reference at the end of the book is an excellent guide to the API entry points that support the OpenGLShading Language. Also included is a convenient Quick Reference Card to GLSL.

shading

OpenGL ES 2.0 Programming Guide

In the OpenGL® ES 2.0 Programming Guide, three leading authorities on the Open GL ES 2.0 interface—including the specification’s editor—provide start-to-finish guidance for maximizing the interface’s value in a wide range of high-performance applications. The authors cover the entire API, including Khronos-ratified extensions. Using detailed C-based code examples, they demonstrate how to set up and program every aspect of the graphics pipeline. You’ll move from introductory techniques all the way to advanced per-pixel lighting, particle systems, and performance optimization.

Coverage includes:

  • Shaders in depth: creating shader objects, compiling shaders, checking for compile errors, attaching shader objects to program objects, and linking final program objects

  • The OpenGL ES Shading Language: variables, types, constructors, structures, arrays, attributes, uniforms, varyings, precision qualifiers, and invariance

  • Inputting geometry into the graphics pipeline, and assembling geometry into primitives

  • Vertex shaders, their special variables, and their use in per-vertex lighting, skinning, and other applications

  • Using fragment shaders—including examples of multitexturing, fog, alpha test, and user clip planes

  • Fragment operations: scissor test, stencil test, depth test, multisampling, blending, and dithering

  • Advanced rendering: per-pixel lighting with normal maps, environment mapping, particle systems, image post-processing, and projective texturing

  • Real-world programming challenges: platform diversity, C++ portability, OpenKODE, and platform-specific shader binaries

    es2.0

OpenGL Distilled

OpenGL® Distilled provides the fundamental information you need to start programming 3D graphics, from setting up an OpenGL development environment to creating realistic textures and shadows. Written in an engaging, easy-to-follow style, this book makes it easy to find the information you’re looking for. You’ll quickly learn the essential and most-often-used features of OpenGL 2.0, along with the best coding practices and troubleshooting tips.

Topics include

  • Drawing and rendering geometric data such as points, lines, and polygons

  • Controlling color and lighting to create elegant graphics

  • Creating and orienting views

  • Increasing image realism with texture mapping and shadows

  • Improving rendering performance

Preserving graphics integrity across platforms

distilled

Gracias

Posted in books, developer, opengl | Tagged | Leave a comment

List Of OpenGL Based Games

These are the list of some top opengl based commercial games:

Call Of Duty 1

This game was developed by Infinity Ward and published by Activision. This game used the id tech 3 engine. Game is based on world war II. Its a first person shooter game. This game won the game of the year for 2003 from several reviewers.

cod-1

Commandos: Behind Enemy Lines

Game was developed by Pyro studios and published by Eidos Interactive. Its a single player real time startegy game.

commandos

Doom 3

Game was developed by id Software and published by Activision. The game uses id Tech 4 engine. Its a first person shooter horror game. The Game was a critical and commercial success for id software with more than 3.5 millions copy sold.

doom3

Half-Life 1

Game was developed by valve software and published by sierra studios. The game used modified version of Quake Engine called GoldSrc engine which is able to render in both OpenGl and Direct3D api. Its a First Person Shooter Game. On its release, critics hailed its overall presentation and numerous scripted sequences, and it won over 51 PC Game of the year awards. It is considered one of the greatest games of all time. This game also set the benchmark in the field off Game AI(Artificial Intellegence) at that period.

half-life

Hitman: Codename 47

Game was developed by IO Interactive and published by eidos interactive. The game uses Glacier engine. Its a third person shooter game.

Hitman1

Unreal Tournament 2004

Game was developed by Epic games. The game used Unreal Engine 2.5. Its a first person shooter game. Game received positive reviews on release. It also received multiplayer game of the year.

unreal

Return to Castle Wolfeinstein

Game was developed by Gray Matter Interactive(Single Player) and Nerve Software(multiplayer) and published by Activision. Games usd id tech 3 engine.

castle

PREY

Game was developed by Human Head Studios and published by 2k Games and 3d realms. The game used modified version of id tech 4 engine. Its a first person shooter game. It received positive reviews and was commercial success, sold more than 1 million copies.

prey

Soldier of Fortune (Series)

First 2 game of the franchise was developed by Raven Software, published by Activision. The game used quake 2 and quake 3 engine.

soldier_of_fortune

There are many other opengl based games. But these are one of my favorites.

Gracias.


Posted in games | Tagged , | 1 Comment

Playstation 3 and Xbox 360 sales numbers

consoles

In year 2008, xbox 360 and playstation 3 were head to head fighting for the top spot. According to the gamer.blorge.com both consoles sold/shipped approximately 10.8 million for the entire year.

The PS3 had a best games line up in year 2008:

METAL GEAR SOLID 4

Metal_Gear_Solid_4_US_Box_Art

RESISTANCE 2

1223352340-Resistance-2-PS3-01

Better games line up was the PS3’s saving grace. According to NPD PS3 sold more than doubled the sales of the XBOX 360 after the metal gear solid 4 was released.

The XBOX 360 also sold as many as the ps3 because of the massive price cut near the end of the year. The XBOX 360 also had a good games like Gears Of War 2 :

gears-of-war-2-coming-1

But the low price moved XBOX 360 head to head with PS3.

With PS3 and XBOX 360 getting sold same amount, the exclusive games: Gears of war 2 and metal gear solid 4 also sold around the same amount around 5 million.

So year 2009 will see the interesting race between xbox 360 and ps3 as ps3 is cutting their price.

According to nexgenwars.com , they are showing the current sales number of consoles:

console_sales

Posted in consoles | Tagged , , , | Leave a comment

My New Game Project : Jungle Riddle

At present i am working on a 2d side-scrolling platform game. It started as a course project but now i want to extend it and make it large.

I have used java and slick library to make this game project. I have put the game demo on my blog page. The project is still in development process. So you can download and play it. Please give the feedback. I am still new to game development so feedback( both positive and negative ) will be appreciated.

So download the game from http://gaanza.com/games/ and play it

please comment your feedback and suggestions here.

it’ll be great help for developing this game further.

Gracias.

Posted in Slick 2D, games, java | Tagged , , | 5 Comments

Getting started making games with java !!

Okie still there are people who thinks java is slow for making commercial and serious games and java is just for casual games. But here i’l show you that java has lot more potential to make serious games.

So now how to get started ??? What libraries or tools to use for making more efficient games ?? There are two libraries which gives you a lot more features to create real time graphics. You can make amazing cool games using these libraries. And what are these libraries ?? They are LWJGL (light weight java game library) and JOGL (java OpenGL). These two libraries gives you the power of opengl graphics library.

LWJGL

The Lightweight Java Game Library (LWJGL) is a solution aimed directly at professional and amateur Java programmers alike to enable commercial quality games to be written in Java. LWJGL provides developers access to high performance crossplatform libraries such as OpenGL (Open Graphics Library) and OpenAL (Open Audio Library) allowing for state of the art 3D games and 3D sound. Additionally LWJGL provides access to controllers such as Gamepads, Steering wheel and Joysticks.

So Is there any game made using LWJGL ??

Yes there is AAA tiltle that has been made using lwjgl. Its TRIBLE TROUBLE by oddlabs, an amazing cool 3d real time strategy game. You can read my post on this game.

source: http://tribaltrouble.com/screenshots?id=14

source: http://tribaltrouble.com/screenshots?id=14

Okie so now where i can find the lwjgl tutorials:

lwjgl tutorial site 1

lwjgl tutorial site 2

(Note: i’ll keep updating the tutorial sites of lwjgl )

JOGL

Java OpenGL (JOGL) is a wrapper library that allows OpenGl to be used in the Java programming language. JOGL is the Sun supported set of Java class bindings for OpenGL. Using OpenGL through JOGL, you will be able to make cool games or model situations that could be too expensive to create.

So any game made with JOGL ???

Yes. Its called JAKE 2. It is the port of Quake 2 game engine from id Software. Here is the screenshot from their ( bytonic Software) site:

source: http://bytonic.de/html/screenshots_1.html

source: http://bytonic.de/html/screenshots_1.html

Okie now i will tell you about some available good engines to make games. All the low level stuff has been done for you. You have to just use the library and take off.

First i’ll start with 2d game engines:

1) Slick 2D : This is the best java 2d game engine based on LWJGL available now. Its an free and Open Source 2d game engine. Many cool games has been made using this game.

2) Golden T Game Engine (GTGE) : Its an advanced cross-platform game programming library written in java programming language.

3) Stencyl

4) JGame

5) PulpCore

Now 3d java engines:

1) jMonkeyEngine : This is the one of the best and popular java 3d graphics engine available now. Its an free and open source engine. JME (jMonkey Engine) is a high performance scene graph based graphics API. Some videos of game made with jMonkeyEngine.

2) Espresso3D : Its an open source high performance real-time 3D engine for the Java(tm) programming language. It aims to be a complete solution for your application with OpenGL rendering, OpenAL audio, collision detection, input, and rendering support.

3) Xith3D : Xith3D is a Java-based 3D engine, centered on gaming.

4) JCPT : jPCT is a free 3D engine/API for Java. Here is one screenshot of games made with JCPT from there site.

source: http://www.jpct.net/screenshots.html

source: http://www.jpct.net/screenshots.html

Okie so thats it. I hope i have give you enough basic info on starting making games with java. So now you make a choice and get started.

Gracias.

Posted in games, java | Tagged , , | Leave a comment

Installing or Setting up JOGL on Ubuntu

gl_java_ubuntu1

Here are the detailed steps to set up or install JOGL on your ubuntu. First of all you have to download the jogl library(according to your machine) from here . I am using Ubuntu 8.04 on intel board so i downloaded jogl-1.1.1-linux-i586.zip.

So extract the zip file. Now open the folder that you have just now extracted. Go to lib folder.

STEP 1: Now you have to copy four .so files i.e libjogl.so, libjogl_awt.so, libjogl_cg.so, libgluegen-rt.so to [javainstalation directory]/jre/lib/i386

Open the terminal window and type: sudo cp libjogl.so /usr/lib/java/jdk1.6.0_13/jre/lib/i386

similarly you have to copy other three .so files.

*you have to provide you java installation path*

jogl1

Now you can check the destination if files has been copied.

jogl21

STEP 2: Now copy jogl.jar and gluegen-rt.jar to [java installation di]/jre/lib/ext

run this command to copy: sudo cp jogl.jar /usr/lib/java/jdk1.6.0_13/jre/lib/ext

simillarly copy gluegen-rt.jar

*you have to provide your java installation path*

jogl3

You can check:

jogl4

STEP 3: SO thats it. Now lets test the simple jogl code.

import javax.media.opengl.GLCapabilities;

public class Hello{
public static void main (String args[]) {
try {
System.loadLibrary(“jogl”);
System.out.println(
“Hello World! (The native libraries are installed.)”
);
GLCapabilities caps = new GLCapabilities();
System.out.println(
“Hello JOGL! (The jar appears to be available.)”
);
} catch (Exception e) {
System.out.println(e);
}
}
}

Now compile this Hello.java and the run it. Here is the output:

jogl-final

So thats it. Now your are off to fly and write your jogl apps.

Thanks.

Posted in Tutorials, developer, java | Tagged , , , | 2 Comments

Alpha Blending using OpenGL with SDL

sdl_opengl

Alpha Blending is a convex combination of two colors allowing for transparency effects in computer graphics. Blending is used to combine the color of a given pixel that is about to be drawn with the pixel that is already on the screen. How the colors are combined is based on the alpha value of the colors, and/or the blending function that is being used. Alpha is a 4th color component usually specified at the end.

Alpha Blending in SDL is slow because its not a hardware accelerated. To get a better performance there is OpenGL which is hardware accelerated. So here i’l show you how to use alpha blending using opengl with sdl.

glColor4f(1.0f,1.0f,1.0f,alpha); // full Brightness, Alpha

glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Blending Function for  translucency based on source alpha value>
 

First line set the color to full brightness with alpha value. An alpha value of 0.0 would mean that the material is completely transparent . A value of 1.0 would be totally opaque. The primitive’s opacity is specified using glColor4*(). RGB specifies the color, and the alpha parameter specifies the opacity.

glEnable(GL_BLEND);                      // Turn Blending on

glDisable(GL_DEPTH_TEST);        //Turn Depth Testing off
 

So this is it what you will required to achieve alpha blending.

Below code is a simple FADE IN/FADE OUT program. When UP arow key is pressed then 2d sprite will fade out and when DOWN key is pressed then 2d sprite will fade in.

alpha

Here is the full Source Code:

#include "SDL.h"
#include "SDL_image.h"
#include "SDL_opengl.h"

#include <stdio.h>

GLuint texture=NULL;     //this is a handle to our texture object
GLenum texture_format=NULL;
GLint nofcolors;

SDL_Event event;

float alpha=1.0f;
bool UP=false;         //Up key is pressed/released
bool DOWN=false;       //DOWN key is pressed/released</em>

<em>int loadImage()
{
SDL_Surface *surface; // this surface will tell us the details of the image

if ( (surface = IMG_Load(“flower.png”)) ) {

// Check that the image’s width is a power of 2
if ( (surface-&gt;w &amp; (surface-&gt;w – 1)) != 0 ) {
printf(“warning: image.bmp’s width is not a power of 2\n);
}

// Also check if the height is a power of 2
if ( (surface-&gt;h &amp; (surface-&gt;h – 1)) != 0 ) {
printf(“warning: image.bmp’s height is not a power of 2\n);
}

//get number of channels in the SDL surface
nofcolors=surface-&gt;format-&gt;BytesPerPixel;

//contains an alpha channel
if(nofcolors==4)
{
if(surface-&gt;format-&gt;Rmask==0×000000ff)
texture_format=GL_RGBA;
else
texture_format=GL_BGRA;
}
else if(nofcolors==3) //no alpha channel
{
if(surface-&gt;format-&gt;Rmask==0×000000ff)
texture_format=GL_RGB;
else
texture_format=GL_BGR;
}
else
{
printf(“warning: the image is not truecolor…this will break “);
}

// Have OpenGL generate a texture object handle for us
glGenTextures( 1, &amp;texture );

// Bind the texture object
glBindTexture( GL_TEXTURE_2D, texture );

// Set the texture’s stretching properties
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

glTexImage2D( GL_TEXTURE_2D, 0, nofcolors, surface-&gt;w, surface-&gt;h, 0,
texture_format, GL_UNSIGNED_BYTE, surface-&gt;pixels );
}
else {
printf(“SDL could not load image.bmp: %s\n, SDL_GetError());
SDL_Quit();
return 1;
}

// Free the SDL_Surface only if it was successfully created
if ( surface ) {
SDL_FreeSurface( surface );
}
}

void drawImage()
{
glClear( GL_COLOR_BUFFER_BIT );   // Clear the screen before drawing

glTranslatef(300.0,200.0,0.0);

glBindTexture( GL_TEXTURE_2D, texture );   // Bind the texture to which subsequent calls refer to

glColor4f(1.0f,1.0f,1.0f,alpha);            // Full Brightness, Alpha
glBlendFunc(GL_SRC_ALPHA,GL_ONE);           // // Blending Function For Translucency Based On Source Alpha Value

glBegin( GL_QUADS );
// Top-left vertex (corner)
glTexCoord2i( 0, 0 );
glVertex3f( -64, -64, 0 );

// Bottom-left vertex (corner)
glTexCoord2i( 1, 0 );
glVertex3f( 64, -64, 0 );

// Bottom-right vertex (corner)
glTexCoord2i( 1, 1 );
glVertex3f( 64, 64, 0 );

// Top-right vertex (corner)
glTexCoord2i( 0, 1 );
glVertex3f( -64, 64, 0 );
glEnd();
glLoadIdentity();

SDL_GL_SwapBuffers();
}

int init()
{
SDL_Surface *screen;

// Slightly different SDL initialization
if ( SDL_Init(SDL_INIT_VIDEO) != 0 ) {
printf(“Unable to initialize SDL: %s\n, SDL_GetError());
return 1;
}

SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL);
if ( !screen ) {
printf(“Unable to set video mode: %s\n, SDL_GetError());
return 1;
}
}

void init_GL()
{
// Set the OpenGL state after creating the context with SDL_SetVideoMode

glClearColor( 0, 0, 0, 0 );

glEnable( GL_TEXTURE_2D );        // Need this to display a texture
glEnable(GL_BLEND);                  // Turn Blending On
glDisable(GL_DEPTH_TEST);         //Turn Depth Testing Off</em>

glViewport( 0, 0, 640, 480 );

glMatrixMode( GL_PROJECTION );
glLoadIdentity();

glOrtho( 0, 640, 480, 0, -1, 1 );

glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}

void clean_up()
{
glDeleteTextures( 1, &amp;texture );</em>

SDL_Quit();
}

int main(int argc, char *argv[])
{
//Make sure the program waits for a quit
bool quit = false;

init();
init_GL();
loadImage();
drawImage();

while( quit == false )
{
if( SDL_PollEvent( &amp;event ) )
{
//If a key was pressed
if( event.type == SDL_KEYDOWN )
{
//Adjust the velocity
switch( event.key.keysym.sym )
{
case SDLK_UP:
UP=true;
break;
case SDLK_DOWN:
DOWN=true;
break;
case SDLK_ESCAPE:
quit=true;
break;
}
}
//If a key was released
else if( event.type == SDL_KEYUP )
{
//Adjust the velocity
switch( event.key.keysym.sym )
{
case SDLK_UP:
UP=false;
break;
case SDLK_DOWN:
DOWN=false;
break;
}
}
}

// If UP key is pressed

if(UP==true){
if(alpha&lt;1.0f)         // make sure alpha value is not greater than maximum value 1.0
alpha+=0.01f;       //increase the alpha value, fade out
drawImage();
}

else if(DOWN==true){    //If DOWN key is pressed
if(alpha&gt;0.0f)       // make sure value of alpha is not less than 0.0f
alpha-=0.01f;      // decrease the alpha value, fade in
drawImage();
}

}

clean_up();
return 0;
}

So thats it. Now you are off to fly.

Gracias.


Posted in Opengl with SDL, Tutorials | Tagged , , | 2 Comments

Setting up java classpath on ubuntu

java_ubuntu

When u install sun’s jdk manually on ubuntu, java classpath doesn’t get set automatically unlike in windows. So when you enter command javac in terminal window, it says “javac  command not found”. So here is the very simple way to set up the classpath for java on ubuntu.

STEP 1 : Open the terminal window.

STEP 2: Type sudo gedit /etc/bash.bash.rc. Press enter.

STEP 3: Now gedit editor will open up. Now at the end of file just write:

PATH=$PATH:/usr/lib/java/jdk1.6.0_13/bin

export PATH

**You have to provide the path of bin folder in java installation deirectory.**

screenshot-12

STEP 4: Now save the file and close the editor and terminal. Open new terminal window and type javac and press enter, all the java options and flags will come up.

Thats it.

Thanks.

Posted in Tutorials, developer, java | Tagged | Leave a comment
  • Become a GaanZa Fan

    GaanZa on Facebook