camelCase
The Case of the Mysterious Camel.
- Reaction score
- 362
So I tried to use GLUT and played around with it and I'm rather satisfied with the experience.
(Yeah, I only took action now, for those who know or remember that I was going to try it)
However, I was wondering how my game loop would look like.
I've got a rough idea but wanna' see if I've got it right before I use it.
Did I get it right? =/
Also, I didn't know how to load images so I found a very old snippet off the internet and updated it for C++.
Anyways, I have a question about textures, image loading and the drawing process.
This is what I *think* I should be doing:
I'm having doubts because in my test (of only one sprite; there's no 'Sprite' class yet),
I did this:
01) load bmp file in main()
02) glBindTexture(GL_TEXTURE_2D, someID); in main()
03) draw one GL_QUADS primitive in render loop
The result is that the texture is still on the primitive despite me only calling 'glBindTexture' once in the main function.
Like, the GL_QUADS primitive is drawn multiple times (even rotated and moved about for fun) but the glBindTexture was only called once.
(Yeah, I only took action now, for those who know or remember that I was going to try it)
However, I was wondering how my game loop would look like.
I've got a rough idea but wanna' see if I've got it right before I use it.
Code:
int main (int arg, char *argv[]) {
//Initialize GLUT
//Set some callbacks
glutDisplayFunc(render);
glutReshapeFunc(reshape);
glutKeyboardFunc(key);
glutSpecialFunc(sKey);
//Enable 2D Texture, Blend..
glutMainLoop();
}
void render () {
//clear
//Umm..
//Thinking of looping through a vector of 'Sprite' classes and displaying them.
//Sprites are just primitives (GL_QUADS) with a texture on them.
//swap buffer
//Timer to call display thingy
//AI, Movement, controls, etc.
}
Also, I didn't know how to load images so I found a very old snippet off the internet and updated it for C++.
Anyways, I have a question about textures, image loading and the drawing process.
This is what I *think* I should be doing:
Code:
01) Load image only once (for each sprite that uses a different image); should get an array of pixels
02) For each call to function render()
a) Loop through a vector of 'Sprite' classes
b) For each 'Sprite' instance do the following:
glBindTexture(GL_TEXTURE_2D, someID);
glColor4f(1.0f, 1.0f, 1.0f, someAlpha);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex2f(/*Insert co-ords here*/);
glTexCoord2f(1.0f, 0.0f);
glVertex2f(/*Insert co-ords here*/);
glTexCoord2f(1.0f, 1.0f);
glVertex2f(/*Insert co-ords here*/);
glTexCoord2f(0.0f, 1.0f);
glVertex2f(/*Insert co-ords here*/);
glEnd();
I'm having doubts because in my test (of only one sprite; there's no 'Sprite' class yet),
I did this:
01) load bmp file in main()
02) glBindTexture(GL_TEXTURE_2D, someID); in main()
03) draw one GL_QUADS primitive in render loop
The result is that the texture is still on the primitive despite me only calling 'glBindTexture' once in the main function.
Like, the GL_QUADS primitive is drawn multiple times (even rotated and moved about for fun) but the glBindTexture was only called once.