Archive Pages Design$type=blogging

"Ray" OpenGL Sample Program in Visual Studio

An user interactive OpenGL Sample Program Written in C/C++ executed in MS Visual Studio.

There are many OpenGL sample program  written in early days of OpenGL Development. These Sample Program or sample code written by many of the authors in top university.

In this post were are going to talk about one such sample code written by David Bucciarelli (tech.hmw@plus.it). This article aims to improvise knowledge of seekers, who want to learn opengl programming with sample code. The download source code from the link in the post for this opengl sample code along with mesa version uploaded to github. Do give author the credit if your are using this opengl sample code in your work projects etc.

Download Sample Code                 Github Mesa Version

1.Overview

The OpenGL Sample Program has been tested in Microsoft Visual Studio Ultimate 2010 and will works in almost all the other version as well. It can be executed on other platforms like linux, mac os etc with some modification.

The program consist of  mainly a light source and a spherical mirror placed on square strips. There are other sections like help section and two maps one for texture of plane and other for texture of sphere.

The Program is user interactive, allow use to give input and get desire output. The user interaction has been code with keyboard functionality of OpenGL.

"Ray" OpenGL Sample Program in Visual Studio

2. The OpenGL Sample Program

The Ray V.10 Written by David Bucciarelli is our OpenGL sample program. You need to have MS visual studio to get started with. Also you need to setup the OpenGL environment to execute the apis provided by them for this opengl sample code. Learn how to setup opengl in MS visual studio in window.

Header Files - First of all include the header files, including glut in the program as we do in "hello world opengl". Thereafter write down the global variable which goes on the way as program progress.

Functions - This program have many functions including the basic opengl function like init, reshape, key and main. We have other functions which is created for drawing the objects. Since we required these function to do our work they are called and used in program.

User Interaction - The key board and special key function is written so user can give input and interact with our program.

3. Coding

There is two object - light source and mirror for reflection. We are going to draw both of them with the help of sphere. Hence we need to call the function for drawing sphere. First of all define the radius for the sphere and then also define the width and height for texture (strips) and it's reflection. Also define the frame rate as we are going to use it as well.

Now we will see all the function one by one (excludes basic functions).

gettime(void) - with use of glutget function this function used to check the status of glut and time with GLUT_ELAPSED_TIME.

calcposobs(void) - defines the position (direction) of observer.

special(int k, int x, int y) - define specil keyboard functions for left, right, up and down navigation keys.

key(unsigned char k, int x, int y) - normal user interaction functions assign to different keys.

printstring(void *font, char *string) -  to print the string.

printhelp(void) - use printstring() and display help box. Font we are using is GLUT_BITMAP_HELVETICA (12 and 18 size).

seelight(float p[3],float dir[3]) - the light source.

colorcheckmap(float ppos[3], float c[3]) - this draw the plane map.

updatecheckmap(int slot) - update plane map with change cause by user interaction.

updatereflectmap(int slot) - update reflection map with change cause by user interaction.

drawbase(void) - Our base is square strips or checkers, this function draws it.

drawobj(void) - draw objects.

dojoy(void)- for joystick functions.

updatemaps(void) - Update maps

draw(void) - Finally draws everything on the screen by rendering objects.

initspherepos(void) - details the sphere position.

inittextures(void) - for textures

initdlists(void) - lists

3. User Interactions

The user interaction in this program is given below -

h - Togle Help

f - Togle Fog

b - Togle Back face culling

p - Togle Wire frame

Arrow Keys (navigation key) - Rotate in left, right, up and down respectively to respective keys

a - Increase velocity

z - Decrease velocity
if(joyavailable)
j - Togle jostick control (Joystick control available)
else
(No Joystick control available)

To move the light source: s - left, d - right, e - far, x - near, w - down r - up

To move the mirror sphere: j - left, k - right, i - far, m - near, u - down o - up

1 - Togle the plane texture map window

2 - Togle the sphere texture map window

4. Final Words

The ray - OpenGLSample Program on compilation and execution will show a checker with one mirror in sphere shape and a light source. There is also two maps in left and right. These maps show the plane and reflection textures. A helps popup like appears in beginning itself that give glimpse of all user interactions in the program. The Youtube video above is showing demo of all the functionality of this program.

If you are keen to learn and become an game programmer this program is especially relevant to you. Also in point of view of exam or project preparation is opengl sample code is an additional help.

Finally, do download this program and comment about it in the comment box.


COMMENTS

Name

3D Bi-Cycle 3D Game 3D Laptop 3D Objects 3D Projects 3D Zoo Algorithm Android Aquarium Bellman-Ford Algorithm B├ęzier curves Block Breaker Blockshooting Bucket Sort C# Chess Clock Code Blocks Colors Complex Project Complex Projects Crab Pong Cross Zero DSAV Escapa Fighter Jet First Come First Serve Flag Flag Hoisting Fluids Font Demo Games Gear Motion GlutDino Glutplane Graphics Editor iOS iPhone Java Java OpenGL Graphics Programming Light Torus Linked List Ludo Board Game Mancala board games Memory blocks game Memory Game Menu Mickey Mouse Minesweeper Miniature Steam Engine moth Motion Blur MoveLight moving car Moving Ship Multiplex Networking Based Project Nuclear Power Plant Olympic opengl c++ examples OpenGL ES OpenGL Tutorial Origami OS Based Projects Paint Paper Folding Particles Drop Path Finding ping pong Pong Game Project Report Projects Report Puzzles qix like Queuqe Random Flowing lines Ray Rigid Body Rings Robot sample c++ opengl code Screen Saver Screen Saver Ship Shadow Cube Shadowfun Ship Iceberg Simple Drawing Simple Haloed Lined Wireframe Simple Move Light Simple Project Simulation SNAKE XENZIA GAME Solar system Sorting Sphere Spot Light Swing Stack Stars Taj Mahal The Edge Game Tic Tac Toe Tower of Hanoi Traffic Signal Transformation Triangular Animation Trippy Tutorial water ripple effects Whirlpool
false
ltr
item
OpenGL Projects: "Ray" OpenGL Sample Program in Visual Studio
"Ray" OpenGL Sample Program in Visual Studio
An user interactive OpenGL Sample Program Written in C/C++ executed in MS Visual Studio.
https://i.ytimg.com/vi/X2LVs34a47E/hqdefault.jpg
https://i.ytimg.com/vi/X2LVs34a47E/default.jpg
OpenGL Projects
http://www.openglprojects.in/2017/09/ray-opengl-sample-program-in-visual-studio.html
http://www.openglprojects.in/
http://www.openglprojects.in/
http://www.openglprojects.in/2017/09/ray-opengl-sample-program-in-visual-studio.html
true
2020194800836807725
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago