Tag Archives: 3D

Simple WebGL example

WebGL is a software library and cross-platform API that extends the capability of the JavaScript programming language.
That brings OpenGL to the web as a 3D drawing context within HTML
Today we present a simple example of using WebGL.
Here, there is an html content, java script and content of WebGL content.
The three main sections are combined.
In section WebGL enter and the fragment shader and vertex shader.
For those who have worked with OpenGL will be easy to recognize specific functions.
Also the source code written for OpenGL format file.

<script type=”text/javascript”>
function shaderProgram(gl, vs, fs) ;

var prog = gl.createProgram(); var addshader = function(type, source) ;
var s = gl.createShader((type == ‘vertex’) ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER); gl.shaderSource(s, source); gl.compileShader(s); if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) ;
throw “Could not compile “+type+ ” shader:\n\n”+gl.getShaderInfoLog(s); } gl.attachShader(prog, s); }; addshader(‘vertex’, vs); addshader(‘fragment’, fs); gl.linkProgram(prog); if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) ;
throw “Could not link the shader program!”; } return prog; } function attributeSetFloats(gl, prog, attr_name, rsize, arr) ;
gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer()); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(arr),gl.STATIC_DRAW); var attr = gl.getAttribLocation(prog, attr_name); gl.enableVertexAttribArray(attr); gl.vertexAttribPointer(attr, rsize, gl.FLOAT, false, 0, 0); } function draw() ;
try ;
var gl = document.getElementById(“webgl”) .getContext(“experimental-webgl”); if (!gl) ;
throw “x”; } } catch (err) ;
throw “Your web browser does not support WebGL!”; } gl.clearColor(0.0, 1.0, 0.0, 1); gl.clear(gl.COLOR_BUFFER_BIT); var prog = shaderProgram(gl, “attribute vec3 pos; “+ “void main() ;
“+” gl_Position = vec4(pos, 2.0);”+ “}”, “void main() ;
“+”gl_FragColor = vec4(0.0, 0.5, 0.1, 1.0);”+ “}” ); gl.useProgram(prog); attributeSetFloats(gl, prog, “pos”, 3, [ -1, 1, 0, 0, 1, 0, 0, -1, 0,1, 0, 0 ]); gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); } function init() ;
try ;
draw();} catch (e) ;
alert(“Error: “+e); } } setTimeout(init, 100);


<canvas id=”webgl” width=”340″ height=”280″></canvas>


The result is this:

Posted in 3D, Programming, WebGL. Tagged with , , .

Ogre 3D and Code::Blocks – first part unfinished

My son has 2 years old.

I had to make a little game to keep him busy.

Little known to push so I used the arrow keys to make it more interesting.

This is the source code.

When you run the project, you will see the following picture:

ogre 3d
The result is :
First Ogre 3D tutorial from Catalin Festila on Vimeo.

Is first try to use Ogre 3D …

Posted in 3D, Game engine, Programming. Tagged with , , .

How to create an executable in Linux using OpenGL.

I will try to show you briefly how to create a Linux OpenGL applications.

We check if the graphics card and settings are done correctly, using the command:

As freeglut devel package provides libraries for OpenGL. Let’s install that package.

Then we see if we have the necessary files.

Let’s try a simple opengl example. This example use glut functions.

The code source is show below with with explanations…

We run the application now.

opengl example tutorial

I wait your opinion and possibly more complex example.

Posted in 3D, Linux, OpenGL, Programming. Tagged with , , , .

Writing a basic game with C++ and OpenGL libs – part 1 .

This is a first part tutorial about linux game using C++ and OpenGL libs.

Writing a C++ game can be difficult.

You will need to focus on program structure and then to know how to create the necessary classes.

Let’s see the files I used:

The main.cpp file is the main program.

This file will make the window program and will deal with the user.

Also this file use OpenGL libs.

Let’s see the source code:

The next two files : display.cpp and display.hpp is used to display the game objects.

I use just one class : Display.

Let’s see the header file display.hpp

… and display.cpp.

You can see the OpenGL source code to make a rectangle.

The next files game.cpp and game.hpp is used to make all game engine working.

The header file game.hpp is:

… and also game.cpp.

Let’s make the Makefile.

This can done well if you know how working g++ compiler.

Use the command to make the binary file:

The resul is this:

simplegame tutorial c++

Posted in 3D, C++, Game engine, OpenGL, Programming. Tagged with , , , , .

Old tips and tricks with Ogre and Blender.

Blender is an open source 3D content creation suite.

Ogre 3D is an 3D library for multiple desktop and mobile platforms.

But is a problem between this tow way.

The last Blender 3D not have yet a script to export the mesh to last Ogre 3D.

What we can do ?. It’s a simple way to make all working.

Use old version of this two and you can also use old video cards.

After you make all settings of code::blocks to use all Ogre librarys, you need to use some tricks.

First , in your source code you need to tell about this:

This means the all three files is using by 3D engine.

On Linux first file – plugins.cfg it is on my distro:

But is because I use an very old video card.

Let’s see the next file – ogre.cfg.

As we see it’s easy way to set some settings like 600 x 400.

The ogre.log it’s use to show the problems.

Let’s see another step in source code:

This load the file – resources.cfg.

Let’s see this file:

The YOUR-USER is your user home folder.

The YOUR-PROJECT it is the folder of project code::blocks.

The OGRE-FOLDER-MEDIA is folder of all files is export by Blender 3D.

Let me show my simple example using NVIDIA FX video card.

The next image show us one 3D object wich is a mesh object.

ogre blend

After I make all materials and mesh with same name.

I use the script to export ogre mesh using the 2.49a version.

ogre blend

The next two images show the settins I need to make to have a mesh.

ogre blend
ogre blend

Also you keep just the object you need to export.

You can use a simple C++ source code to render with Ogre Engine.

ogre blend

Posted in 3D, Blender 3D, C++, Game engine, Linux, Programming. Tagged with , , , , , .