GLFW

Started by
8 comments, last by arrow 20 years ago
Not sure if i should ask it in this forum but does anyone use GLFW and if so... you think it''s better then using GLUT. I''m doubting ... should i use GLUT of GLFW. The nicyies like globes can be implemented easily but subwindowing is missing in GLFW i think. 3D as never seen before.. that is... it is still not to be seen ;-)
3D as never seen before.. that is... it is still not to be seen ;-)
Advertisement
I use GLFW and I recommend it too!! I haven''t really used GLUT but SDL used I before. I know GLUT is used kinda weird way. But GLFW is very easy and result very clean code. It also gives very easy texture loading, extension loading & testing, high precision timer, now joystick support too and everything nice.



-----------
RacingTreme - for fun multiplayer racing:
http://users.utu.fi/stkibr
Hey, I''m writing a quick program for school using GLFW, but I''ve ran into a bit of a problem with loading several textures at once.

What I''m doing is throwing these:
  glBindTexture(GL_TEXTURE_2D, texid[0]);  glfwLoadTexture2D("mars-posz.tga", 0);  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 

into my initialization function (and I''ve defined GLuint texid[3] too). Then in my draw function I do this:
glBindTexture(GL_TEXTURE_2D, texid[0]); 

then draw the appropriate quad, setting texture coordinates and all.

Now, I''m having two problems with this. First, all the images load succesfully in the initialization, but when I go into the draw function, only the last image loaded will show (and I am indexing texid correctly too). My guess is that glfwLoadTexture2D(...) deletes the last texture when it is called again, although I''m not sure. Also, the textures change my lighting. I''m not sure what''s going on there, but my regular white light (and grey object) appear red/brown after loading the texture (which is a rendering of the surface of mars). I noticed that when I set GL_FRONT_FACE to GL_POINT that the texture no longer renders, same with GL_LINE, does this have anything to do with it? Any help is well appreciated.
     GLuint tex[3];          glGenTextures( 1, tex );  // You forgot about this?     glBindTexture( GL_TEXTURE_2D, tex[0] );     glfwLoadTexture2D( "Mars.tga", GLFW_BUILD_MIPMAPS_BIT );     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );      // How do you know that the texture is loaded successfully if you didn''t even debug it?     ...     GLfloat rotate = 0.0f;     glPushMatrix();     glRotatef( rotate, 0.0f, 0.0f, 1.0f ); // Rotate around the z-axis     glBegin( GL_QUADS );     glTexCoord2f( 0.0f, 0.0f ); glVertex3f( 0.0f, 0.0f, 0.0f );     glTexCoord2f( 0.0f, 0.0f ); glVertex3f( 0.0f, 0.0f, 0.0f );     glTexCoord2f( 0.0f, 0.0f ); glVertex3f( 0.0f, 0.0f, 0.0f );     glTexCoord2f( 0.0f, 0.0f ); glVertex3f( 0.0f, 0.0f, 0.0f );     glEnd();     glPopMatrix();     rotate += 0.1f;     if( rotate >= 360.0f )        rotate = 0.0f;


Anyways. I enjoy using GLFW. I love it. It is much better than GLUT. Initiation is much easier than SDL but I sorta prefer SDL since there is much more control in SDL->OGL than in GLFW->OpenGL. Glut just sucks.

-----------------------
"In reality God is a comedian but his audience are too afraid to laugh."
-----------------------"In reality God is a comedian but his audience are too afraid to laugh."
I've got glGenTextures in there too, I guess I should have included it in my code above.

//global spaceGLuint texid[6];...//intitGL  glGenTextures(6, texid);  glBindTexture(GL_TEXTURE_2D, texid[0]);  glfwLoadTexture2D("mars-posz.tga", 0);  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);  glBindTexture(GL_TEXTURE_2D, texid[1]);  glfwLoadTexture2D("mars-negx.tga", 0);  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);  glBindTexture(GL_TEXTURE_2D, texid[2]);  glfwLoadTexture2D("mars-posy.tga", 0);  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);  glBindTexture(GL_TEXTURE_2D, texid[3]);  glfwLoadTexture2D("mars-negy.tga", 0);  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);  glBindTexture(GL_TEXTURE_2D, texid[4]);  glfwLoadTexture2D("mars-posx.tga", 0);  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);  glBindTexture(GL_TEXTURE_2D, texid[5]);  glfwLoadTexture2D("mars-negz.tga", 0);  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);  glEnable(GL_TEXTURE_2D);...//draw  glLoadIdentity();  //DRAW SKYBOX  glDisable(GL_LIGHTING);  glDisable(GL_CULL_FACE);  glBegin(GL_QUADS);  //-Z  glBindTexture(GL_TEXTURE_2D, texid[0]);  glNormal3f(0,0,1);  glTexCoord2f(0,0);	glVertex3f(-25,-25,-25);  glTexCoord2f(1,0);	glVertex3f(25,-25,-25);  glTexCoord2f(1,1);	glVertex3f(25,25,-25);  glTexCoord2f(0,1);	glVertex3f(-25,25,-25); ... and so on for the rest of the skybox, going throught texid[0]-texid[5].


I know that "technically" I don't know all the textures are loading correctly since I don't have any proper error-checking yet; however, when I check the images individually (ie. comment out all the other image load calls), then they each work fine. I will be adding error-checking, but I'm mostly sure this is not related to my other problems.


[edit] - how'd you get that nice CSS-style box? I'll edit mine so it's not so obtrusive.
-Thanks for the {source} info aftermath.

[edited by - OpenGL Aaron on March 25, 2004 5:19:37 PM]
To make a good-looking syntax-highlighted box, enclose your source code in {source} and {/source} where a { is an [ and } is ]
Rate me up.
You have to enable texturing before you plot the points. Like so:

glPushMatrix();glEnable( GL_TEXTURE_2D );glBindTexture( GL_TEXTURE_2D, texid[0] ); // texid[ the texture you want to draw ]// Then you plot the points.glDisable( GL_TEXTURE_2D );glPopMatrix();


---
Reticent rapine is underway...
---Reticent rapine is underway...
Sorry, yes, I''ve also got that in there. I enable texturing right after all the gflwLoadTexture calls with glEnable(GL_TEXTURE_2D). If anyone would like to take a look at the full source code, I''d be happy to send it.
I would suggest that you initialize the rest of openGL before you load any textures. Take a look at some of the tuts on this site & see the ordering that they have. They work every time
Yes, yes. I'm initializing OpenGL correctly as well.
I'm modifying a .obj loader I wrote for school last semester. It loads the objects fine, it renders them fine, everything works exactly as it should. The only problem I have is with texturing and I'm not sure if that's because of something I'm doing or something with GLFW.

I'm trying to make a skybox for now, just a simple texturing exercise, but it's not working. All the tutorials I've found on NeHe about texturing use a single texture and repeat it for every face of the cube - I can do that fine. What I'm trying to do is load a different texture for each face of the cube. I can load the textures, I can texture the quads of the cube, but regardless of which name I'm binding to "glBindTexture2D", it always uses the last tex image that I loaded. An odd side-problem is that the .obj model I have loaded seems to be affected by the color of the textures, despite that I'm texturing the quads after I've already rendered the model.. but that's a secondary concern for me right now.

[edit]
Alright, I fixed the secondary problem; I only enable texturing (glEnable(GL_TEXTURE_2D) ) just before texturing the quad, then disabled it directly after. I also set glTexEnvf(...) to GL_DECAL to disable the lighting on that, so that problem is taken care of. Still in the process of figuring out what's wrong with the "always using last texture image regardless of which target is bound" in case anyone is interested.

[edit 2]
Woohoo! I fixed it. Okay, I'll demonstrate with code how it should be done:
//draw  glLoadIdentity();  //DRAW SKYBOX  glDisable(GL_LIGHTING);  glDisable(GL_CULL_FACE);    //-Z  glBindTexture(GL_TEXTURE_2D, texid[0]);  glBegin(GL_QUADS);glNormal3f(0,0,1);  glTexCoord2f(0,0);	glVertex3f(-25,-25,-25);  glTexCoord2f(1,0);	glVertex3f(25,-25,-25);  glTexCoord2f(1,1);	glVertex3f(25,25,-25);  glTexCoord2f(0,1);	glVertex3f(-25,25,-25); glEnd();glBindTexture(GL_TEXTURE_2D, texid[1]);glBegin(GL_QUADS);...glEnd();...(etc)

So what I had to do was isolate each quad. For each quad I have to bind a texture, start glBegin(GL_QUADS), do all the vertices and stuff, then end that segment with glEnd(), then repeat for every single quad of the cube.

[edited by - OpenGL Aaron on March 25, 2004 9:17:07 PM]

This topic is closed to new replies.

Advertisement