Jump to content
  • Advertisement
Sign in to follow this  
Florin Cazan

[Solved] OpenGL game project

This topic is 3559 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have to make a project for faculty. The project has to be a game made with OpenGL, so I chose to make a game similar to Ballance, because I think it isn't that hard. No animations, no AI, just some physics, collision detection and pretty graphics to compensate for the simplicity. I'm a beginner in OpenGL programming so I want to use this thread for help during the game development. Since fixed function pipeline is obsolete, I want to make everything I can with shaders, using GLSL. So far, I managed to texture a teapot using GLSL, but I don't know how to texture more than one object: Image As you can see only the teapot is textured. ----------------------------------------------------------------------- This is the relevant code: The main() function which is also the initialization function: glutDisplayFunc(renderScene); glutIdleFunc(renderScene); glutReshapeFunc(changeSize); glutKeyboardFunc(processNormalKeys); glEnable(GL_DEPTH_TEST); glClearColor(0.0f, 0.7f, 0.8f, 1.0f); loadBitmap("Data/reaper.bmp", texture[0]); glewInit(); setShaders(); glutMainLoop(); ----------------------------------------------------------------------- The loadBitmap() function: void loadBitmap(LPTSTR szFileName, GLuint &texid) { HBITMAP hBMP; BITMAP BMP; glGenTextures(1, &texid); hBMP = (HBITMAP) LoadImage(GetModuleHandle(NULL), szFileName, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE ); GetObject(hBMP, sizeof(BMP), &BMP); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glBindTexture(GL_TEXTURE_2D, texid); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 3, BMP.bmWidth, BMP.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits); DeleteObject(hBMP); } ------------------------------------------------------------------------- The renderScene() function: void renderScene(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(0.0f, 2.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); glTranslatef(-1.3f, 0.0f, 0.0f); glRotatef(a, 0, 1, 0); glutSolidTeapot(1); glLoadIdentity(); gluLookAt(0.0f, 2.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); glTranslatef(1.3f, 0.0f, 0.0f); glRotatef(-a, 0, 1, 0); glutSolidCube(1); a += 0.5f; glutSwapBuffers(); } ------------------------------------------------------------------------- The Vertex Shader: void main() { gl_Position = ftransform(); gl_TexCoord[0] = gl_MultiTexCoord0; } --------------------------------------------------------------------------- The Fragment Shader: uniform sampler2D tex; void main() { gl_FragColor = texture2D(tex, gl_TexCoord[0]); } --------------------------------------------------------------------------- I've searched the internet for answers but the solutions found are like pieces of puzzle to me. My questions are: 1. Do I have to use different shaders for different objects? 2. Do I have to use samplers? If so, in what function do I put the code? 3. How do I create another texture? glEnable(GL_DEPTH_TEST); glClearColor(0.0f, 0.7f, 0.8f, 1.0f); loadBitmap("Data/reaper.bmp", texture[0]); loadBitmap("Data/leaves.bmp", texture[1]); Is this correct? I know that is a long post and the questions are stupid but I spent a whole day trying to figure this out and got nothing. [Edited by - Florin Cazan on October 22, 2008 4:40:03 AM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!