Jump to content
  • Advertisement
Sign in to follow this  
ishkabible

toggle fullscreen with glfw

This topic is 2784 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

pretty simple question, how do i toggle full screen with glfw? i tried calling glfwOpenWindow with GLFW_FULLSCREEN passed to it but it doesn't seem to be working. cant find anything that specifys how to toggle fullscreen so im asking here.

here is the code im working with

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glfw.h>

#include <IL/il.h>
#include <IL/ilu.h>
#include <IL/ilut.h>

#include <irrKlang/irrKlang.h>

#include <iostream>
#include <fstream>
#include <string>
#include <deque>

#include <boost/timer.hpp>

using namespace irrklang;
using boost::timer;

int main() {
glfwInit();
if( !glfwOpenWindow( 512, 512, 8, 8, 8, 8, 8, 8, GLFW_WINDOW ) ) {
glfwTerminate();
return 0;
}
glfwSetWindowTitle("GLFW Application");
ilInit();
iluInit();
ilutInit();
ilutRenderer(ILUT_OPENGL);
ISoundEngine* engine = createIrrKlangDevice();
engine->play2D("prondisk.xm", true);
glEnable( GL_TEXTURE_2D );
glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
int width, height;
int frame = 0;
bool running = true;
ILuint texid;
GLuint tex;
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
ilGenImages(1, &texid);
ilBindImage(texid);
ilLoadImage("Zombie.png");
ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH),
ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE,
ilGetData());
ilDeleteImages(1, &texid);
while(running) {
glfwGetWindowSize( &width, &height );
height = height > 0 ? height : 1;
glViewport( 0, 0, width, height );
glClearColor( 1.0f, 0.0f, 0.0f, 0.0f );
glClear( GL_COLOR_BUFFER_BIT );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluOrtho2D(0,width,height,0);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glBegin(GL_QUADS);

glTexCoord2i(0, 0); glVertex2i(0, 0);
glTexCoord2i(0, 1); glVertex2i(0, 64);
glTexCoord2i(1, 1); glVertex2i(64, 64);
glTexCoord2i(1, 0); glVertex2i(64, 0);

glTexCoord2i(0, 0); glVertex2i(0, 32);
glTexCoord2i(0, 1); glVertex2i(0, 96);
glTexCoord2i(1, 1); glVertex2i(64, 96);
glTexCoord2i(1, 0); glVertex2i(64, 32);

glEnd();
glfwSwapBuffers();
if(glfwGetKey(GLFW_KEY_SPACE)) glfwOpenWindow( width, height, 8, 8, 8, 8, 8, 8, GLFW_FULLSCREEN);
running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED);
}
glDeleteTextures(1,&tex);
glfwTerminate();
return 0;
}




Share this post


Link to post
Share on other sites
Advertisement
What do you mean it when you say it doesn't seem to work? What is happening when you hit the spacebar? Is the window being destroyed and the program closing? Is the window staying how it was before you hit spacebar?

Also I believe you need to close a window before you open another one with glfwCloseWindow(). GLFW only deals with single windows as far as I know. Just as a heads up though, doing so will destroy your OGL context so you'll want to make sure any resources that you've allocated through OpenGL are renewed accordingly.

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!