mrnutty 761 Senior Poster

Here is one way of doing it.

int Array[5] = {0};
	int num(0); //the number the use will input;

	for(int i = 0; i < 5; i++)
	{
		cout<<"Enter value# "<<i<<":  ";
		cin >> num;
		if( num >=5 && num <= 15) //put number into array only if its within bounds
			Array[i] = num;
		else 
		{
			cout<<"Number should be from 5 to 15. Try again\n";
			i = i - 1; //if not subtract 1 from i to reset it
		}
	}
mrnutty 761 Senior Poster

not sure what you are asking for. Maybe some code would help.

mrnutty 761 Senior Poster

common mistake :

while (qAnswer = 'y');

should be

while (qAnswer == 'y');

You understand the difference between '=' and '==' right?

mrnutty 761 Senior Poster

Could you give us more information , so we can answer your question
better. Not that most will hand you the answer without seeing you
suffer:)

mrnutty 761 Senior Poster

Now try a recursion functions for this job.

1) Find a base case.
2) Find a pattern.
3) Recurse pattern until base case is reached.

Also no need to worry about the little details right now. Just keep it in mind.

mrnutty 761 Senior Poster

You might want to try a more general approach, where the user
gets to input the number of rows for the tree.

mrnutty 761 Senior Poster

just to help start you off (from how I interpret the problem ):

Steps :

1) declare variable for input
2) get user's input via cin
3) have a class ready to pass the variable to its consturctor
4) inside constructor decide which class the students get
5) print the class the student gets

mrnutty 761 Senior Poster

use ifstream

then :

int main()
{
     cout<<"Enter file name (with extension): "
     char filename[1024] = {0};
     cin >> filename;
   ifstream iFile(filename);
  ...//do some stuff
}
mrnutty 761 Senior Poster

I tried to install the devil library but I am getting some
errors. Here are the steps that I am taking to install it :

Let me see if I did this correctly :

Steps :

1) download DevIL 1.7.8 for windows 32 bit
2) extract the info to c:\devil folder
3) open visual studio 2008 tool-&gt;options.
4) goto VC++ Directories
5) change the options to show Include Files
6) Add file directory -- C:\devil\Include
7) change the option to show Library Files
8) Add file directory -- c:\devil\Lib
   (note) there is a unicode folder inside of Lib folder
9) Click Ok
10) click alt-F7 for project options
11) goto c++ tab and under Addition Include Directory add C:\devil\Include
   (not sure if thats needed)
12) under c++ tab--code generation--make sure Runtime library is on multi-thread debug dll(/MDd)

13) click ok.

Then on my program add some or all header :
#include<IL/il.h>
#include<IL\ilu.h>
#include<IL\ilut.h>

from this in my functions ilInit() works, but iluInit() causes a linking error, as well as ilutInit().

Am I doing this correctly

Even if I don't use ilu or ilut, I need ilu, and it does not give me an linking error, but when I try to load an image

with ilLoadImage(L"starts.bmp") it return false. Even if I try absolute path like
ilLoadImage("C:...\project\loadimgwithlib\start.bmp") it won't work.

Anyone have it working with visual studio 2008 and with openGL?

mrnutty 761 Senior Poster
//Are used to determine if certain settings are enabled/disabled
//0->disabled
//1->enabled
"static int useRGB = 1;
static int useLighting = 1;
static int useFog = 0;
static int useDB = 1;
static int useLogo = 0;
static int useQuads = 1;"    

//used for delay
static int tick = -1;
//determine if object is moving
static int moving = 1;

//color constants
#define GREY	0
#define RED	1
#define GREEN	2
#define BLUE	3
#define CYAN	4
#define MAGENTA	5
#define YELLOW	6
#define BLACK	7

//material color property
static float materialColor[8][4] =
{
  {0.8, 0.8, 0.8, 1.0},
  {0.8, 0.0, 0.0, 1.0},
  {0.0, 0.8, 0.0, 1.0},
  {0.0, 0.0, 0.8, 1.0},
  {0.0, 0.8, 0.8, 1.0},
  {0.8, 0.0, 0.8, 1.0},
  {0.8, 0.8, 0.0, 1.0},
  {0.0, 0.0, 0.0, 0.6},
};

//light position
static float lightPos[4] =
{2.0, 4.0, 2.0, 1.0};
#if 0
static float lightDir[4] =
{-2.0, -4.0, -2.0, 1.0};
#endif
//light properties
static float lightAmb[4] =
{0.2, 0.2, 0.2, 1.0};
static float lightDiff[4] =
{0.8, 0.8, 0.8, 1.0};
static float lightSpec[4] =
{0.4, 0.4, 0.4, 1.0};

//quads vertices
static float groundPlane[4] =
{0.0, 1.0, 0.0, 1.499};
static float backPlane[4] =
{0.0, 0.0, 1.0, 0.899};

//fog settings
static float fogColor[4] =
{0.0, 0.0, 0.0, 0.0};
static float fogIndex[1] =
{0.0};

//shadow patterns
static unsigned char shadowPattern[128] =
{
  0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,  /* 50% Grey */
  0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
  0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
  0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, …
MosaicFuneral commented: Code tags. -1
mrnutty 761 Senior Poster

Not sure what you mean. Maybe an example would help

mrnutty 761 Senior Poster

well a ball is a sphere and keeping z = 0 will make it a circle.

mrnutty 761 Senior Poster

I am using c++/opengl. Can someone help me with a wrapper
for a 2d ball representation. I have one but its not complete.
I need other stuff like momentum and collision response.
Can you help me implement this?

mrnutty 761 Senior Poster

No its not what I meant. When I run the .exe by browsing it does not
display the textures but just the quads and the color associated with
it. If I can't use the .exe correctly then neither can anyone else
that I share it with. My question is How can I correctly transport
the .exe application with everything loaded in the .exe correctly

mrnutty 761 Senior Poster

How could one share a .exe that loads textures. I am using
c++ and openGL. I want to share the .exe that I made using
rapidshare.

mrnutty 761 Senior Poster

Thanks, and btw I sent you a PM ancientDragon

mrnutty 761 Senior Poster

Will try it.

mrnutty 761 Senior Poster

Well the title does says clock() function. Let me be more clear,
so no wise comment is made. I have a object spinning based on
the time the user presses the right key, If the user stops pressing
the right key then I need to reset the clock() function to 0. If there
is another way please suggest.

mrnutty 761 Senior Poster

Is there a way to reset the clock function?

mrnutty 761 Senior Poster

What you want to achieve will take a lot code than what you might
expect. I would recommend to use '*' as un-fliped mode so the
user wont get confused.

mrnutty 761 Senior Poster

I know that it returns the remainder but what happens when say :

x% y,

where x,y is int and x<y. I see that results in x;

For example, 3% 101232 = 3 and similarly 3%y, where y is
greater than 3 yields 3. Why is that>

Just wonder the details of what goes on.

mrnutty 761 Senior Poster

quote : Unless this is for a class, I would recommend using C++

This is for practice, learning other language than c++.

mrnutty 761 Senior Poster

I'm sorry, there is no "real " error. I am just query about c#
inputs, because I've been use to c++.

I see that they differ in return value, c++ returns both char or
numbers, while c# returns chars. I also realize that sometimes
the stream contains more junk, so I had to use a dummy readline().

Like this snippet :

Console.WriteLine("Would you like to be X or O :  ");

            P1_ID = (char)Console.Read();

            //Dummy reader
            Console.ReadLine();

Notice the Dummy reader. Is there a way to get around this.
I mean even in the simplest case, say where in a while loop
I ask the use to input a value, the loops reads the value and skips
a few iterations because of the junk in the stream.
So for example, if I do this :

while(true)
        { 
            Console.WriteLine("Enter something :  ");
              int in =  Console.Read();
               Console.WriteLine("you entered {0}",in);
        }

The stream returns more than one value?

mrnutty 761 Senior Poster

I just started a few days ago. I am troubled with the input
in c#, even though I got it to work. Any comment would be
helpful. Its a Number Guessing game and a tic-tac-toe game.

using System;

namespace GAME
{
    #region NUMBER GUESSING GAME
    public class Number_Guess
    {
        public static void HiLow()
        {
            int guessNum = -1;

            string gNum;

            Random rand = new Random();

            int minRan = rand.Next(10);
            int maxRan = rand.Next(50,150);

            int goal = rand.Next(minRan, maxRan);

            int numOfGuess = 0;

            Console.WriteLine("Your object it to guess the random number from {0} to {1}\n\n",minRan,maxRan);

            do
            {

                Console.WriteLine("What will you guess   :  ");

                gNum = Console.ReadLine();

                guessNum = int.Parse(gNum);

                if (guessNum == goal)
                {
                    Console.WriteLine("You guessed correct!\n\n Press a key to continue ...");
                    string x = Console.ReadLine();
                    
                    break;
                }

                else if (guessNum > goal)
                {
                    Console.WriteLine("You guessed too high\n");
                    ++numOfGuess;

                }

                else
                {
                    Console.WriteLine("You guessed too low\n\n");
                    ++numOfGuess;
                }

            } while (guessNum != goal);


        }

    }
    #endregion
    #region TIC-TAC-TOE
    public class BOARD_GAME
    {
        const int GAME_STRT = 0;
        const int GAME_OVER = 1;
        const int RESET = 2;
        

        public static void Tic_Tac_toe()
        {

            Console.Title = "Tic-Tac-Toe";

            //Create a The main GameBoard 3x3
            char[] GameBoard = new char[9]
            {
                '1','2','3',
                '4','5','6',
                '7','8','9'
            };

            //Initialize
            char P1_ID = 'X';
            char Comp_ID = 'O';
            int GameState = GAME_STRT;
            int choice = -1;
            
            Random rand = new Random();

            Console.WriteLine("Would you like to be X or O :  ");

            P1_ID = (char)Console.Read();

            //Dummy reader
            Console.ReadLine();

            if (P1_ID == 'O' || P1_ID == 'o' …
mrnutty 761 Senior Poster

I am trying to rotate the object by a input of key.
I dont know why the object is not rotating.

I used glRotatef(x,0,0,1); //where x is declared as float :

here is my code :

#include<GL/glut.h>



GLfloat x = 10;

void initGL()
{
    glEnable(GL_DEPTH);
	glDepthFunc(GL_LEQUAL);
	glClearDepth(1.0f);

}

void reshape(int width,int height)
{
	glViewport(0,0,width,height);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	gluPerspective(45.0,(float)width/(float)height,5.0,250.0);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}

void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	
	glTranslatef(0,0,-10);
	glRotatef(x,0,1,0);
	glutSolidCube(1.0);

	glutSwapBuffers();
	glFlush();
	glutPostRedisplay();
	
}

void keyboard(unsigned char key, int x, int y)
{
	switch(key)
	{
	case 27: exit(0);break;
	case' ': x++;
	}

}

void specialFunc( int key, int x, int y)
{
	switch(key)
	{
	case  GLUT_KEY_UP : x+=1;break;
	case  GLUT_KEY_DOWN:
	case  GLUT_KEY_LEFT:
	case  GLUT_KEY_RIGHT:;
	}

}

int main(int argc, char ** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);
    glutInitWindowSize(500,500);
    glutInitWindowPosition(300,200);
    glutCreateWindow("OPENGL");
    
	initGL();

    glutDisplayFunc(display);
	
	glutReshapeFunc(reshape);
	
	glutKeyboardFunc(keyboard);
	glutSpecialFunc(specialFunc);
  
	glutMainLoop();

	return 0;
}
mrnutty 761 Senior Poster

He's not asking how to send it to someone else, he's asking why when he does send it to someone else it won't work on their computer, to which the reason is it's not able to link to the resources necessary, 1 of the easiest ways to solve that problem is to just statically link in all the necessary code.

I just thought this he should give this a try. It works somethimes.

mrnutty 761 Senior Poster

try to zip it up. If you have visual studio 8. Then build your code.

Then open my computer. Go to C: , then find visual studi 2008. Then
find you project name. Then search the folder for .exe file.
Clik on it to make sure it works. Then right click the file, and go to send to, then Compressed(zipped) Folder. Then send it to whomever.

mrnutty 761 Senior Poster

how would you seperate a character in a string.

For example :

string ="2x^2+8"

how would i seperate the string into '2' 'x' '^' '2' '8'.

so I could find its derivative.

mrnutty 761 Senior Poster

example of cin.get().

say a file called num.txt contains the following :
12345677700234.

using cin.get() would first get the number 1, then it may be easier to imagine an arrow pointing to the number 2 , because the number 1 has already been extracted. Then using cin.get() again would ger the number 2, then an imaginary arrow would point to the next number, 3, so if you use cin.get() , then you would get the number 3, and the an imaginary arrow would point to the number 4, then if you use cin.get, you get 4, and so on.

here is an example.

file num.txt contains [123445];

//include all needed libraries.
//preprosessors directives.

int main()
{
ifstream file("num.txt)
...
...

int num;

while(!fil.eof())
{
cin.get(num);
cout<<num;
}

return 0;

}
mrnutty 761 Senior Poster

hi,

I am confused on why my texture came out a different color?

I have a bmp file of a cloud, skyblue color on the background and white clouds. BUt when i load it on a square the color becomes
pinkish for background and cloud is white? Why pink-ish?

here are my settings:

glBindTexture(GL_TEXTURE_2D, textureNum);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);

		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

		glTexEnvf(GL_TEXTURE_2D,GL_TEXTURE_ENV_COLOR,GL_MODULATE);
		glTexImage2D(GL_TEXTURE_2D,0,4,infoheader.biWidth,infoheader.biHeight,0,GL_RGBA,GL_UNSIGNED_BYTE,filesize);
		gluBuild2DMipmaps(GL_TEXTURE_2D,4,infoheader.biWidth,infoheader.biHeight,GL_RGBA,GL_UNSIGNED_BYTE,filesize);

		free(filesize);

and my main.cpp( part of it) :

glBegin(GL_QUADS);

	glTexCoord2f(1,1);		glVertex3f(1.0f,0.0f,2.0f);
	glTexCoord2f(0,1);		glVertex3f(1.0f,-2.0f,2.0f);
	glTexCoord2f(0,0);		glVertex3f(-1.0f,-2.0f,2.0f);
	glTexCoord2f(1,0);		glVertex3f(-1.0f,0.0f,2.0f);
mrnutty 761 Senior Poster

Know :

C/C++
Python
java
OpenGL
DirectX


Depending on you situation, your son should learn the list above , although c++ and opengl/directx should be more important than others.

Also check out community colleges, and talk to them for what courses they offers, with regards to programming. Or even check out their websites. There are lots of resources online as well. You
could definitly learn a lot from the internet as well.

mrnutty 761 Senior Poster

Varying the y or x did not work either?

    for(float xc=0.0, yc = 0.0; xc <= 5; xc+=0.1,yc+=0.1 )
    {
        //xCor = sqrt( pow(five,two) - pow(yc,two) );
        yCor = (double)sqrt( pow(five,two) - pow(xc,two) );

        glVertex2f(xc,yCor);
    }

    glEnd();
mrnutty 761 Senior Poster

Thanks, the problem was 1) the .bmp file was not a power of 2 and
i did not include, .bmp, in art. Thank you very much .

mrnutty 761 Senior Poster

hi,

I am trying to draw a circle without using cos,sin;

Mainly by the formula x^2+y^2 = r^2;

this is my code , but for some reason its not working. any help?
note: I thought this code would draw the upper halve fo the portion.

float xCor,yCor;
xCor=yCor =0.0;

float five,two;
five = 5.0;
tow = 2.0;

for(float xc=0.0, yc = 0.0; xc <= 5; xc+=0.1, yc+=0.1)
		{
			xCor = sqrt( pow(five,two) - pow(yc,two) );
			yCor = sqrt( pow(five,two) - pow(xc,two) );

			glVertex2f(xCor,yCor);
		}
mrnutty 761 Senior Poster

thanks matt, but for some reason the image is not sticking to the polygon.

in my texture.h file I have :

extern int num_texture;

extern int Loadbitmap(char* filename);

in my texture.cpp file , I have :

#include<iostream>
#include <stdio.h>
#include <windows.h>
#include <GL/glut.h>
#include "texture.h"

using namespace std;


int num_texture = -1;

int Loadbitmap(char* filename)
{
	unsigned char *l_texture;
	int i,j=0;

	FILE* file;

	BITMAPFILEHEADER fileheader;
	BITMAPINFOHEADER infoheader;

	RGBTRIPLE rgb;

	num_texture++;

	file = fopen(filename,"rb");
	if(file == NULL)//if file does not exist return -1
			return -1;
	fread(&fileheader,sizeof(fileheader),1,file);
	fseek(file,sizeof(fileheader),SEEK_SET);
	fread(&infoheader,sizeof(infoheader),1,file);

	l_texture = (byte* ) malloc(infoheader.biWidth * infoheader.biHeight * 4); 
    memset(l_texture, 0, infoheader.biWidth * infoheader.biHeight * 4);

  for (i=0; i < infoheader.biWidth * infoheader.biHeight; i++)
   { 
      fread(&rgb, sizeof(rgb), 1, file); 

      l_texture[j+0] = rgb.rgbtRed; // Red component
      l_texture[j+1] = rgb.rgbtGreen; // Green component
      l_texture[j+2] = rgb.rgbtBlue; // Blue component
      l_texture[j+3] = 255; // Alpha value
      j += 4; // Go to the next position
   }

  fclose(file);

  glBindTexture(GL_TEXTURE_2D,num_texture);
  
   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
   
   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
   glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
   
   glTexImage2D(GL_TEXTURE_2D, 0, 4, infoheader.biWidth, infoheader.biHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, l_texture);
   gluBuild2DMipmaps(GL_TEXTURE_2D, 4, infoheader.biWidth, infoheader.biHeight, GL_RGBA, GL_UNSIGNED_BYTE, l_texture);

	free(l_texture);

	return num_texture;

}

and in my main.cpp I have

#include<iostream>
#include<cstdlib>
#include<GL/glut.h>
#include<windows.h>
#include"texture.h"

using namespace std;



void InitGL()
{
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	//glEnable(GL_COLOR_MATERIAL);
	//glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE);
	//glClearColor(0.0f,0.0f,0.0f,1.0f);
	//glClear(1.0f);
	//glEnable(GL_LIGHTING);
	//glEnable(GL_LIGHT0);
	//glEnable(GL_LIGHT1);
	//glEnable(GL_NORMALIZE);
	glEnable(GL_SMOOTH);
	glClearColor(0.0f,0.0f,0.0f,0.0f);
	
	
	Loadbitmap("art");

}

void EnableLight()
{
	//NOT SET UP YET...
}

void handleResize(int width, int height)
{
	glViewport(0,0,width,height);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	gluPerspective(45.0f,(double)width / (double)height,1.0f,200.0f);

}

void keyboard(unsigned char key,int x, int y)
{
	switch(key)
	{ …
mrnutty 761 Senior Poster

hey,

I am just learning textures in OpenGl, from a certain tutorial site :

http://www.spacesimulator.net/tut3_texturemapping.html

the site had a good tutorial for texture, but after loading the .bmp picture, it goes to create its own function for vertex3f and such ( I think). In any matter, I have not learned that way of style, not yet anyway, but it seems that now I am stuck on how to apply the texture to polygons.

Can you help me?

here is the code where I loaded , made room and associated the
bmp file with openGl, all i need help now is to lather the texture
onto the a polygon, say a box for instance, please help me finish the rest.

this is my loadimage.cpp file

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<GL/glut.h>
#include<windows.h>

using namespace std;


int num_texture = -1;

int LoadBitmap(char* filename)
{
	unsigned char *l_texture;
	int i,j=0;

	File* file;

	BITMAPFILEHEADER fileheader;
	BITMAPINFOHEADER infoheader;

	RGBTRIPLE rgb;

	num_texture++;

	if(file = (fopen(filename,"rb") == NULL)//if file does not exist return -1
			return 0;
	fread(&fileheader,sizeof(fileheader),1,file);
	fseek(file,sizeof(fileheader),SEEK_SET);
	fread(&infoheader,sizeof(infoheader),1,file);

	l_texture = (byte* ) malloc(infoheader.biWidth * infoheader.biHeight * 4); 
	memset(l_texture,0, malloc(infoheader.biWidth * infoheader.biHeight * 4);

  for (i=0; i < infoheader.biWidth * infoheader.biHeight; i++)
   { 
      fread(&rgb, sizeof(rgb), 1, file); 

      l_texture[j+0] = rgb.rgbtRed; // Red component
      l_texture[j+1] = rgb.rgbtGreen; // Green component
      l_texture[j+2] = rgb.rgbtBlue; // Blue component
      l_texture[j+3] = 255; // Alpha value
      j += 4; // Go to the next position
   }

  fclose(file);

  glBindTexture(GL_TEXTURE_2D,num_texture);
  
   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, …
mrnutty 761 Senior Poster

thanks matt. Seems like you're the only one around here that knows about openGL. Thank you very much. The normal function helped , fixed the axies calculation. But in a tutorial i seen a normal for each vertex to better the effects. Can you explain how to set normal for each vertex. I mean the cordinates for each face of the box.
ex( glNormal3f(0.0f,0.0f,1.0f); //is for the front. but what about each glNormal for each vertex. what would be glNormal parameter, and how would I know what parameter to set?

mrnutty 761 Senior Poster

Ovbiously this code is doing something else than what I wanted it to do. I wanted it to shine red on the left of the screen, whenever a part of the box comes near its axis,
and shine , green on the right of the screen, whenever a part of the box comes near its axis, and a spec of white on the right as well. And also when the color shines its backwards, meaning shining green on left and red on right?

please help.

I can see that all of the color works but, its not producing the result i wanted. any help?

here is the code :

#include<iostream>
#include<cstdlib>

#include<GL/glut.h>

using namespace std;


void keyHandler(unsigned char key, int x, int y)
{
	switch(key)
	{
	case 27 : exit(0);

	}

}

void InitRendering()
{
	glEnable(GL_DEPTH_TEST);
	glShadeModel(GL_SMOOTH);
	glEnable(GL_COLOR_MATERIAL);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glEnable(GL_LIGHT1);
	//glEnable(GL_NORMALIZE);

}
 void handleResize(int w, int h)
 {
	 glViewport(0,0,w,h);

	 glMatrixMode(GL_PROJECTION);
	 glLoadIdentity();

	 gluPerspective(65.0,(double)w/(double)h,1.0,200.0);



 }

GLfloat Yrot = 0.0;

 void disp(void)
 {
	 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	 glMatrixMode(GL_MODELVIEW);
	 glLoadIdentity();
	glPushMatrix();


	GLfloat amb[] = {0.2f,0.2f,0.2f,1.0f};
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT,amb);

	GLfloat dif[] = {1.0f,0.0f,0.0f,1.0f};
	GLfloat difPos[] = {-1.0f,0.5f,3.0f,1.0f};
	glLightfv(GL_LIGHT0,GL_DIFFUSE,dif);
	glLightfv(GL_LIGHT0,GL_POSITION,difPos);

	GLfloat dirColor[] = {0.0f,1.0f,0.0f,1.0f};
	GLfloat dirPos[] = {-1.0f,0.5f,3.0f,0.0f};
	glLightfv(GL_LIGHT1,GL_DIFFUSE,dirColor);
	glLightfv(GL_LIGHT1,GL_POSITION,dirPos);

	GLfloat spec[] ={0.5f,0.5f,0.5f,1.0f};
	GLfloat position[] = {1.0f,0.5f,0.0f};
	glLightfv(GL_LIGHT1,GL_SPECULAR,spec);
	glLightfv(GL_LIGHT1,GL_POSITION,position);
	//glLightfv(GL_LIGHT0,GL_AMBIENT,amb);
	

	glColor3f(1.0f,1.0f,0.0f);
	//GLfloat mColor[] = {0.0f,1.0f,0.0f,1.0f};
	//glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mColor);
		glTranslatef(0.0f,0.0f,-2.0f);
	glRotatef(Yrot,0.0f,1.0f,0.0f);
	glBegin(GL_QUADS);
		
			//FRONT
			glVertex3f(-0.5f,-0.2f,0.0f);
			glVertex3f(0.5f,-0.2f,0.0f);
			glVertex3f(0.5f,0.2f,0.0f);
			glVertex3f(-0.5f,0.2f,0.0f);
			
			//RIGHT SIDE
			glVertex3f(0.5f,-0.2f,0.0f);
			glVertex3f(0.5f,-0.2f,-0.5f);
			glVertex3f(0.5f,0.2f,-0.5f);
			glVertex3f(0.5f,0.2f,0.0f);
			
			//BACK SIDE
			glVertex3f(-0.5f,-0.2f,-0.5f);
			glVertex3f(0.5f,-0.2f,-0.5f);
			glVertex3f(0.5f,0.2f,-0.5f);
			glVertex3f(-0.5f,0.2f,-0.5f);

			//LEFT SIDE
			glVertex3f(-0.5f,-0.2f,-0.5f);
			glVertex3f(-0.5f,-0.2f,0.0f);
			glVertex3f(-0.5f,0.2f,0.0f);
			glVertex3f(-0.5f,0.2f,-0.5f);
	glEnd();
glPopMatrix();
	glutSwapBuffers();
 

 }

 void update(int value)
 {
	Yrot+=2.0;
		if(Yrot > 360)
			Yrot = …
mrnutty 761 Senior Poster

I am practicing lighting and smooth shading. THe problem is that this code only shines the light for front and the right side , but when the objected is rotated, it shines at constant position (the front and right) and not to the side that are on the positioned light.
If it is still unclearn i am saying that the directed light and position light does not shine at the position as its supposed to and only shines on the front and the right side. please help.

if you need the code ask.

mrnutty 761 Senior Poster

i am writing a code that will rotate the polygon but it seem as if it is not working any help?

#include<iostream>
#include<Gl/glut.h>
#include<cstdlib>
using namespace std;

GLfloat fPent = 0.0; // for rotating pentagon;
GLfloat fSqr = 0.0; // for rotating square;

void handleKeyPress(unsigned char key, int x, int y)
{
		if(key == 26)
			exit(1);
}


 int InitGL(GLvoid)
{
	
	glShadeModel(GL_SMOOTH);//Enable smootheness
	glClearColor(0.0,0.0,0.0,0.5);//Clear any color to black
	glClearDepth(1.0f);//we clear depth.
	glEnable(GL_DEPTH_BUFFER_BIT);//we turn on depthness
	glDepthFunc(GL_LEQUAL);//the type of test we will use for depth test
	glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); // 
	glEnable(GL_COLOR_BUFFER_BIT);//we enable color buffer.
	
	return true;
}

GLvoid ReSizeGLScene(GLsizei width, GLsizei height)	
{
	if(height == 0)
		height = 1;

	glViewport(0, 0, width, height);	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
	
}

void disp()
{
	 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear color and depth to what we set it before;
	 glMatrixMode(GL_MODELVIEW);
	 glLoadIdentity();

	glTranslatef(-1.0,0.0f,-6.0f);
	glRotatef(fPent,1.0f,0.0f,0.0f);

	glBegin(GL_TRIANGLES);					// Start Drawing A Triangle
		glColor3f(1.0f,0.0f,0.0f);			// Set Top Point Of Triangle To Red
		glVertex3f( 0.0f, 1.0f, 0.0f);			// First Point Of The Triangle
		glColor3f(0.0f,1.0f,0.0f);			// Set Left Point Of Triangle To Green
		glVertex3f(-1.0f,-1.0f, 0.0f);			// Second Point Of The Triangle
		glColor3f(0.0f,0.0f,1.0f);			// Set Right Point Of Triangle To Blue
		glVertex3f( 1.0f,-1.0f, 0.0f);			// Third Point Of The Triangle
	glEnd();

		glLoadIdentity();

		glTranslatef(1.0f,0.0f,1.0f);
		glRotatef(fSqr,1.0f,0.0f,0.0f);

	glBegin(GL_QUADS);
	
		glColor3f(0.0f,0.0f,0.0f);
	glVertex3f(-1.0f, 1.0f, -10.0f);	
		glColor3f(0.0f,1.0f,0.0f);
	glVertex3f( 1.0f, 1.0f, -10.0f);	
		glColor3f(0.0f,0.0f,1.0f);
	glVertex3f( 1.0f,-1.0f, -10.0f);	
		glColor3f(0.6f,0.4f,1.0f);
	glVertex3f(-1.0f,-1.0f, -10.0f);	
		glEnd();

		

		glutSwapBuffers();
		
		fPent += 1.0;
		fSqr -= 0.4;
		

		glFlush();
		
}


int main(int argc,char**argv)
{
		glutInit(&argc,argv);
		glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
		glutInitWindowSize(500,500);
		glutInitWindowPosition(300,100);
		glutCreateWindow("My first polygons with colors and rotations");
		glEnable(GL_DEPTH_TEST);
		glutDisplayFunc(disp);
		glutKeyboardFunc(handleKeyPress);
		glutReshapeFunc(ReSizeGLScene);

		glutMainLoop();

		return 0;
}
mrnutty 761 Senior Poster

first off iostream.h is not standard so dont bother using it. use
#include<iostream> instead.

to solve your problem try doing this :

#include<iostream>

using namespace std; //important.

int main(){

cout<<"Hello world."<<endl;

return 0;
}
Rashakil Fol commented: Way to not read the thread before replying and way to not use code tags. -1
William Hemsworth commented: What he said. And what you posted was wrong anyway, you don't need "using namespace std;" -1
mrnutty 761 Senior Poster

Figured out the problem. Needed to add glFlush() at the end of the drawing function.

I'll leave this up here so other can see it,but I will delete this soon.

mrnutty 761 Senior Poster

You should look at the unit circle.

So obj 1 has a velocity of 0 in direction 3pi/4(south) and you want it to face northeast towards the obj 2.

so you need to rotate obj one anti clockwise on the angle pi/4.

this is a hint try to figure it out from there, if you get stuck then reply back.

mrnutty 761 Senior Poster

First of, You should get very familar with C++( if you don't know it already). Then after you are comfortable with C++. Then you will know how to make text based game.

note: atleast learn up to classes in C++. Then go to youtube or google text game in C++. Then they will help you how to start it off.

Practice C++,Practice C++,Practice C++,Practice C++,Practice C++,Practice C++,Practice C++,Practice C++,Practice C++,Practice C++, oh and one more thing Practice C++ :)

mrnutty 761 Senior Poster

hi,

I started learning openGl yesterday. I made a simple program that supposed to create a triangle and a square, but its not working properly, any help please?

#include<iostream>
#include<Gl/glut.h>
#include<cstdlib>
using namespace std;

void handleKeyPress(unsigned char key, int x, int y)
{
		if(key == 26)
			exit(1);
}


 int InitGL(GLvoid)
{
	
	glShadeModel(GL_SMOOTH);//Enable smootheness
	glClearColor(0.0,0.0,0.0,0.5);//Clear any color to black
	glClearDepth(1.0f);//we clear depth.
	glEnable(GL_DEPTH_BUFFER_BIT);//we turn on depthness
	glDepthFunc(GL_LEQUAL);//the type of test we will use for depth test
	glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); // 
	glEnable(GL_COLOR_BUFFER_BIT);//we enable color buffer.
	
	return true;
}

GLvoid ReSizeGLScene(GLsizei width, GLsizei height)	
{
	if(height == 0)
		height = 1;

	glViewport(0, 0, width, height);	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
	
}

void disp()
{
	 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear color and depth to what we set it before;
	 glMatrixMode(GL_MODELVIEW);
	 glLoadIdentity();

	glTranslatef(-1.5,0.0f,-6.0f);
	
	glBegin(GL_TRIANGLES);
	
		glVertex3f(0.0f,1.0f,0.0f);
		glVertex3f(-1.0f,-1.0f,0.0f);
		glVertex3f(1.0f,-1.0f,0.0f);
		
		glEnd();

		glTranslatef(3.0f,0.0f,0.0f);

	glBegin(GL_QUADS);
		glVertex3f(-1.0f,1.0f,0.0f);
		glVertex3f(1.0f,1.0f,0.0f);
		glVertex3f(1.0f,-1.0f,0.0f);
		glVertex3f(-1.0f,-1.0f,0.0f);

	glEnd();

	glutSwapBuffers();
}


int main(int argc,char**argv)
{
		glutInit(&argc,argv);
		glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
		glutInitWindowSize(500,500);
		glutInitWindowPosition(300,100);
		glutCreateWindow("My first polygons");
		glEnable(GL_DEPTH_TEST);
		glutDisplayFunc(disp);
		glutKeyboardFunc(handleKeyPress);
		glutReshapeFunc(ReSizeGLScene);

		glutMainLoop();

		return 0;
}
mrnutty 761 Senior Poster

.

mrnutty 761 Senior Poster

Thank you everyone for you help, especiall you styXYZ, properly named to answer this question since your last 3 letter associated with 3 deminsions.

mrnutty 761 Senior Poster

stuxyz, thanks for your reply. To me it's now a bit clearer of how much math/what math is stressed upon, when making 3d modeled games.
But, let me ask one more question, although a person might need many types of math for making any type of games, or complex application, should the algorithm for it be overly complex. I mean, since its math, i am guessing the algorithm, say for making a ball thrown into a hoop by a 6' person (basketball), should be straight forwad right--(velocity,position,momentum,..physics, plus the size of the ball compare to average person in the game..)?

would the algorithm be tricky, or maybe it should be for faster excuetion...

mrnutty 761 Senior Poster

Well, one thing is for sure... in a 3D game, Trig is pretty much vital... for example, using a sound library that works in 3D. You have to calculate how far you are from the event that makes the sound... then the velocity of the item and speed, to determine how much to increment the volume by as the object "whizzes" by your head... I remember working on an MMORPG, and you have to calculate your distance from any point on the map.... which is something crazy, like the sqrt of x, y, and z squared.

Realistically, just to make a game, not so much. However, making one of those realtime mmo's or FPS... probably a lot more than you would first think.

thanks, I can see how that might take math to compute moving sounds. Although at first , I might think the pythagorean therom would be better easier to use than trig.

mrnutty 761 Senior Poster

I am just curious, just how much of math do one really needs in order to make, say space invaderes, or pacman....WOW,..NBA LIVE 2009?

It's not that i am bad at math or anything, in fact I am pretty good at it and still learning, calc.II. BUt i am curious, since I do not have any 3d graphic skills ( trying to master c++ first), I really dont know just how much math does it really take to make a game.

note: when i ask how much math, i don't mean adding or subtracting.., instead i mean something like do i need complex algorithm using math properties.

thanks , and happy 09.