Zaki Mirza’s Blog


… About software and beyond!

Jeff Atwood’s Top 6 Lists of top 10 programming lists

Jeff Atwood’s Coding horror has been my favourite blog lately (though i have just been following it since not long). Hes been bloging since a while writing on all sorts of computing/IT stuff. Here is what he posted few days ago that i found really very intresting and though provoking about programming and how to improve on it. Ill write a more indepth review for the blog in near future.


Filed under: general, programming

About Quizes and Blog

  1. Quizes are not for showing how good/bad I am. They are not for you to proove how good/bad you are. They are for discussions on certain ideas relating computer programming in general, data structures/algorithms in paticular. If you come up with something really thoughful to discuss, I would love to accept that.
  2. This is not a barrack. No this is not a barrack. We really dont give guns. We really are not going on war. No hostility will be tolerated in any form.
  3. Feel free to spread the blog around. I’d love to have as many people around as possible. The more people who have a passion of progression and want to take others with like minds with them, they are most welcome (infact im looking for such people to keep this blog alive). It requires input from everyone. Provided (which is ideal) that I do get a lot of input, ill come up with a forum as well.
  4. You are not your code. (from Jeff Atwood’s blog. One of my very favourites.)

Filed under: general

Quiz #2 – Tree Problem (DS)

My brother put this question to me a couple of years ago. Then i found myself having to deal with it in my datastructures project. here it is: 

Suppose you have a tree. A binary tree (for something like simplicity :p). You are traversing it (using infix, postfix or prefix) to search for a node. You find your required node. You just realized that you need to know the path from this node back to the root node (and/or vice versa). Given the following description of the structure of the tree node that you “cant” change:

struct node{Data data; node *right,*left;};

what will you strategy be to tackle this problem.

To make it more intresting (or maybe just the application of the above problem) suppose you find the node A and a node B in consecutive searches. Now what will your strategy be to show a path from A to B. (not neccesarily from the root of the whole tree, but possibly).

 Dont peek in the comments please. Think about it. Rule of pinky: Be honest to yourself atleast :p

You can make any assumption, but dont forget to state it with your solution.

Filed under: programming, quiz

Quick C++ Quiz #1

Im starting a little section for C++ quizes. Im nowhere near a C++ wizard. Just something i learn from here and there and ill put em up as food for thought for all my readers. Part 2 ready as well lets c.

consider this :


 int main(int argc, char** argv){
int a();

Whats the problem with above code if any. Also, what do you think the above code does (or tries to do?) what is ‘a’?

Filed under: C++, programming, quiz

using glDrawElement for more logically building 3d objects in opengl

Working on CG again, i was seeing how we have to do a lot of things in glBegin() and glEnd block to create simple to complex objects. What i just found out is the use of Vertex arrays in openGL. (checkout the Red Book Chapter 2). Ill just give one example of this.

Suppose you want to create a cube (im sure most of them are already hating the sight of the “cube” :p). Simple one would go on create the 6 faces using GL_QUADS like:


.. and so on for rest of the faces traversing the vertices in counter-clockwise direction. thats like, 6×4 24 function calls! (imagine the overhead, on the PC and on… well ur hands:p). So GL has this really cool mechanism of vertex arrays. I wont go in details since the red-book is “the” definitive guide on openGL stuff but heres the example. First you make an array of the vertices like: (oh im lazy so im just pasting it from my own code, basically here width,height and depth are comming in the constructor, CP is a point with x,y,z fields).

//vertex definition of cube
GLfloat va[] = {
cp.x-width/2.0f, cp.y+height/2.0f, cp.z+depth/2.0f,
cp.x+width/2.0f, cp.y+height/2.0f, cp.z+depth/2.0f,
cp.x+width/2.0f, cp.y-height/2.0f, cp.z+depth/2.0f,
cp.x-width/2.0f, cp.y-height/2.0f, cp.z+depth/2.0f,
cp.x-width/2.0f, cp.y+height/2.0f, cp.z-depth/2.0f,
cp.x+width/2.0f, cp.y+height/2.0f, cp.z-depth/2.0f,
cp.x+width/2.0f, cp.y-height/2.0f, cp.z-depth/2.0f,
cp.x-width/2.0f, cp.y-height/2.0f, cp.z-depth/2.0f
//face drawing indices
GLubyte ia[] = {
/* front */
0,4,7,3, /* left */
3,7,6,2, /* botom */
3,1,5,6, /* right */
6,7,4,5, /* back */
5,4,0,3 /* top */
if you work these indices out, youll end up with a solid cube. (remember the join-the-dots game aah i miss them ). So now we have the vertices, we have an indices list that says how to join the dots. we know we’ll do the quads here. What now?First we enable the openGL vertex array state.glEnableClientState(GL_VERTEX_ARRAY);Then we tell where our vertices are:glVertexPointer(3,GL_FLOAT,0,_vertices);and then we draw this element using out indicesglDrawElements(_drawMode,_numIndices,GL_UNSIGNED_BYTE,_indices);(GL_UNSIGNED_BYTE tell what is the type of indices, _numIndices is the number of indices in the array. can be less than the acutal array but then only those vertices will be traversed. and _drawMode is my variable, i set it to GL_QUADS for solid cube.)So basically we have made a cube with a lot less function calls and in a lot logical manner. Check out what these functions do and how to best utilize them in the red-book chapter 2. i have the red book for version 1.4 of OpenGL (i dunno yet if they will be available  in previous versions).The possibilities are endless using this technique. There are also ways to specify color array for the element like this as well. 

Be cautious though. make sure you change the glVertexPointer everytime you make a new object. Also to disable the vertex array mode when you are done with it. Also dont use glDrawElements within GlBegin and glEnd because glDrawElement will do it for you. if you do it just like i wrote here, you might get a single colored tasteless cube which doesnt even look like a cube. try using GL_COLOR_ARRAY to color different vertices. Ill put of a post about lighting in openGL soon (as soon as i learn it myself :p)

Filed under: C++, CG, opengl, programming

Blog Stats

  • 104,758 landed here so far...
March 2007
« Feb   Apr »


Error: Twitter did not respond. Please wait a few minutes and refresh this page.

RSS Google Shared Items

  • An error has occurred; the feed is probably down. Try again later.

RSS Google Reader Starred Items

  • An error has occurred; the feed is probably down. Try again later.

Top Clicks

  • None