Saturday, March 28, 2020

Quiz Game in C Part 3: Final Game Play and score

In previous articles, we created functions, multi-dimensional character array to store questions, options, and answers. Up to this point, we have everything ready to finish gameplay.
Here we will use the following techniques:

  • Create for loop to display question one by one
  • Create another infinite loop inside for loop to check the answer given by the user. The loop breaks only if the user-provided an answer is within options (a, b, c and d)  otherwise it will loop infinitely. 
  • Calculate the score for the correct answer provided.
  • Use gotoxy to manage text indentation.

Quiz game in C Part 2: Multi-dimensional C array

In this article, we will discuss the gameplay() function but not all only the usages of one dimension, two-dimension, and third dimension character array. Choosing the correct dimension of the array is very important to store information effectively. We have to display a question, four options and store the correct answer to compare the answer provided by the user. Remember these three information are connected to each other if we mismatch the order then the game will go wrong. 
Here, we will declare three character array to store questions, four options, and answer in the same order of the array index.

Question is a string which is an array of character and we will ask 10 questions in total. We create a two-dimension character array, the first index is a total number of questions i.e 10 and the second index is the length of a string.
    char question[10][250];
    strcpy(question[0], "This is question no 1");
    strcpy(question[1], "This is question no 2");
    strcpy(question[2], "This is question no 3");
    strcpy(question[3], "This is question no 4");
    strcpy(question[4], "This is question no 5");
    strcpy(question[5], "This is question no 6");
    strcpy(question[6], "This is question no 7");
    strcpy(question[7], "This is question no 8");
    strcpy(question[8], "This is question no 9");
    strcpy(question[9], "This is question no 10");
We can't assign string using "=" to the two-dimension array and correct way to use it is strcpy() function.

Quiz Game in C part 1 - Flow Chart and Main Menu

Application Flow Chart:

Start: Quiz program start
Main Menu: Program display menu to the user to start the game or to quit.
User Input: The application stops to get user input.
Decision Tree: If user input is S then Quiz game start else if user input is Q then the program will quit.
Quiz Game: User gets 10 questions one by one and each correct score is marked as 1.
Display Score: It display final score after ending the game and the user is directed to the main menu.
Stop: End of the game.

Monday, August 26, 2013

Basic GLFW Tutorials with C++

GLFW (OpenGL FrameWork) is open source library to create OpenGL Window and multi-platform  too. Very easy to manage OpenGL context and event with GLFW. It is specially suitable for game development. GLFW doesn't render 3D scene for that you have to use OpenGL library function. GLFW help to create window , handle keyboard , mouse and joystick events. This tutorials is for those who are new to OpenGL and GLFW. By the end of this tutoirals series understand the basic knowledge about OpenGL and handling events with GLFW.

Tutorials 1: Setup GLFW in Code::Blocks IDE in Windows Machine

Tutorials 2:  Introduction to GLFW

Tutorials 3: Drawing Basic Shapes

Tutorials 4: Transformation: Translation, Rotation and Scalling

Tutorials 5: Texture Mapping 

Saturday, July 27, 2013

Modern OpenGL Tutorial Series

Modern OpenGL are different than ancient opengl version before 2.0. After opengl 2.0 vetex shader and fragment shader became compulsory. It is little bit difficult for beginner to start.

All chapter include basic concept of Modern OpenGL and especially focus on beginner. After going through all the chapter user can get concept of shader, drawing shapes, perspective projection, transformation, color, texture mapping and load 3D model wavefront OBJ.

Download all the code as a zip from here:

All the code in this series of articles is available from github: You can download a zip of all the files from that page, or you can clone the repository if you are familiar with git.

Modern OpenGL tutorial 3D model .obj loader/parser with C++ and GLM

When you need to draw a more advanced object like character, house, terrain, vehicles we can't pass the vertices by ourselves for these object so we have to use the 3D model and model are simply the meshes made of one or more number of vertices. There are many 3D modeling software one of them is blender which is open source also. Blender help to create the model and export it into different file format like .obj, 3ds, md2 etc among them I choose the .obj (wave front obj) file which is very simple. OBJ only contain vertex, normal, texture and other material information. It doesn't support animation for animation we can use  3ds, md2  3Dmodel. There are many library to load 3D model.

All the code in this series of articles is available from github:  You can download a zip of all the files from that page, or you can clone the repository if you are familiar with git.

 In this articles I will show you how to write your own .obj model parser.

Friday, June 21, 2013

Modern OpenGL tutorial Texture Mapping Example source code

Texture mapping technique haven't change in Modern OpenGL. If you are experience in ancient version of OpenGL you might have done Texture mapping which is similar to here.Only difference is adding the extra variable to the vertex shader and fragment shader. Texture memory lie in video memory similar to VBO which is uploaded to OpenGL. Two things we have to pass in vertex shader and fragment shader. One is texture co-ordinate to define how to map on vertex and another texture color data to define the color of every pixel.Many article are there in internet about texture.Some of the great article are below.

  1. Texture Maping and Bitmap  This example use the OpenGL version 1.5 where VBO and VAO are absent.
  2. Texture is not Picture Article presents whats the texture is about.
  3. Texure This is the blog form where I learn about Modern OpenGL. 
All the code in this series of articles is available from github:  You can download a zip of all the files from that page, or you can clone the repository if you are familiar with git.