Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


chayanvinayak

Member Since 17 Jul 2011
Offline Last Active Aug 01 2011 05:53 PM

Topics I've Started

Loading BMP file using C++

28 July 2011 - 05:46 PM

Hello ,

Is there any good example code with explanation for loading BMP file for texturing using C++ ?
I tried to take a look at Nehe.gamedev.net and they are using some old GLAUX.h which does not exist any more and one of the other video tutorial website does not show how they loaded the bmp files they just showed how to apply loaded bmp file for texturing.

Thanks
Chayan Vinayak

Loading BMP file using C++

28 July 2011 - 05:45 PM

Hello ,

Is there any good example code with explanation for loading BMP file for texturing using C++ ?
I tried to take a look at Nehe.gamedev.net and they are using some old GLAUX.h which does not exist any more and one of the other video tutorial website does not show how they loaded the bmp files they just showed how to apply loaded bmp file for texturing.

Thanks
Chayan Vinayak

gluLookAt(z=0) objects z=0 but they r not visible

22 July 2011 - 01:37 PM

Hello,

I have written a simple program to learn camera, perspective,projection and model_view matrix.

In this program :
- I am setting the camera to look at (0,0,0) :x=0,y=0,z=0
and placing the camera at (0,0,-20) : x=0,y=0,z=-20

- first I place all the objects at z=0
But they are not visible.
They should be visible bcz camera is looking at z=0 and
all the objects are at z=0

- as soon as I place objects at z=-2 they get visible.


Here is my code :




#include <stdio.h>
#include <glut.h>
int fov = -2;


void handleResize(int w, int h){
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45,double(w)/double(h),1, 100 );
printf("%d\n",fov);
gluLookAt(0,0,0,0,0,-20,0,1,0);
}

void handleKeypress(unsigned char key,int x, int y){

switch(key){
case 27:
exit(0);
case 56:
fov+=2;
glutPostRedisplay();
break;
case 50:
fov-=2;
glutPostRedisplay();
break;
}
printf("Key: %d : Z: %d\n",key,fov);
}
void init(){
glEnable(GL_DEPTH_TEST);
}

void drawScene(){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f,0.0f,float(fov));

glBegin(GL_POINTS);
glVertex3f(20.0f, 20.0f, 0.0f);
glEnd();
glBegin(GL_QUADS);
glVertex3f(2.0f, 2.0f, 0.0f);
glVertex3f(-2.0f, 2.0f, 0.0f);
glVertex3f(-2.0f, -2.0f, 0.0f);
glVertex3f(2.0f, -2.0f, 0.0f);
glEnd();
glutSwapBuffers();



}

void main (int argc, char** argv){

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);
glutInitWindowSize(400,400);
glutCreateWindow("Chayan Vinayak's OpenGL tutorial ");
init();
glutDisplayFunc(drawScene);
glutKeyboardFunc(handleKeypress);
glutReshapeFunc(handleResize);
glutMainLoop();


}

gluPerspective() OpenGL

17 July 2011 - 08:04 PM

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

In gluPersepective() function we define near clipping. In most of the cases we define near clipping as 1.0 which means anything which is beyond 1.0 or which has Z co-ordinate value less than 1.0 will not be drawn then why are the primitives or points are drawn or visible in the screen which have -5.0( or any other negative value for Z-axis)

eg.

glBegin(GL_POINTS);
glVertex3f(10.0f, 20.0f, -5.1f);
glEnd();


Thanks

Basic OpenGL

17 July 2011 - 08:03 PM

Hello,
I am trying to draw a very basic OpenGL program which is supposed to draw a point on the screen. But it is not drawing anything.
Following is the code.

Thanks



#include <stdio.h>
#include <glut.h>


void handleResize(int w, int h){
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45,double(w)/double(h),1, 100 );
}

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

}
void init(){
glEnable(GL_DEPTH_TEST);
}

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

glBegin(GL_POINTS);
glVertex3f(10.0f, 20.0f, -5.1f);
glVertex3f(50.0f, 50.0f, 5.1f);
glEnd();

glBegin(GL_QUADS);
glVertex3f(10.0f, 20.0f, -5.0f);
glVertex3f(50.0f, -50.0f, 5.1f);
glVertex3f(-10.0f, 20.0f, -5.1f);
glVertex3f(-50.0f, -50.0f, 5.1f);
glEnd();

glutSwapBuffers();

}

void main (int argc, char** argv){

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);
glutInitWindowSize(400,400);

glutCreateWindow("Chayan Vinayak's OpenGL tutorial ");
init();

glutDisplayFunc(drawScene);
glutKeyboardFunc(handleKeypress);
glutReshapeFunc(handleResize);
glutMainLoop();

}

PARTNERS