• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Sonec Borec Nguyen

Switching from Fullscreen to Window

2 posts in this topic

Hi guys,
I'm new in OGL, I found how to Enter and Leave Fullscreen in two different solutions:
1. glutFullScreen() and glutLeaveFullScreen() (doesn't work ... maybe old dll)
2. glutEnterGameMode and glutLeaveGameMode
Now I have maybe badly constructed code, but works for me without fullscreen, if I want Fullscreen, I must change variables "width" and "height" and then run glutFullSreen method.
I want fullscreen on key F when I draw ogl window with menu (simply switch fullscreen/window on key "F").

Now I have:
[CODE]
// MAIN.cpp - MAIN PROGRAM
#include "main.h"
// Variables
float cam1=5; // Camera position
float x=4250,y=-30,z=-7390; // Map position
float carx=-4220,cary=0,carz=7210; // Car position
float width=800.0, height=600.0; // Window size
bool h1=false,k1=false,l1=false,f1=false; // F key for Help menu
// Font settings
const int font1=(int)GLUT_BITMAP_HELVETICA_12;
const int font2=(int)GLUT_BITMAP_HELVETICA_18;
// Light settings
GLfloat lightAmb[3] = {0.1f, 0.1f, 0.1f};
GLfloat lightDiff[3] = {1.0f, 1.0f, 1.0f};
GLfloat lightPos[4]={0.0f, 0.0f, 0.0f, 1.0f};
// Models variables
GLMmodel* car = NULL;
GLMmodel* map = NULL;
// Keyboard Function
void Keyboard(unsigned char key, int xx, int yy) {
glutPostRedisplay();
switch(key) {
case 'h': // Show/hide help menu
if(h1==false) h1=true;
else h1=false;
break;
case 'k': // Left-side camera
k1=true;
cam1=-103;
x=4400;
break;
case 'l': // Right-side camera
l1=true;
cam1=113;
x=4100;
break;
case 'f' : // Fullscreen ON/OFF
if(f1==false) {
f1=true;
}
else {
f1=false;
}
break;
case 27 : // Stop program
exit(0);
}
}
// Keyboard UP Function
void KeyboardUp(unsigned char key, int xx, int yy) {
switch(key) {
case 'k': // K key up
k1=false;
cam1=5;
x=4250;
break;
case 'l': // L key up
l1=false;
cam1=5;
x=4250;
break;
}
}
// Keyboard HOLD DOWN Function
void myIdleFunc(void) {
glutPostRedisplay();
if(k1) { // K key pressed
cam1=-103;
x=4400;
}
if(l1) { // L key pressed
cam1=113;
x=4100;
}
}
// Initializing models
void initModels(void) {
// Set car model
car = glmReadOBJ("Models/audi-tt.obj");
if (!car) exit(0);
glmFacetNormals(car);
glmVertexNormals(car, 90.0);
// Set map model
map = glmReadOBJ("Models/map.obj");
if (!map) exit(0);
glmFacetNormals(map);
glmVertexNormals(map, 90.0);
}
// Text Function
void renderBitmapString(float x, float y, void *font,string str) {
const char *c;
glRasterPos2f(x, y); // Text position
for (c=str.c_str(); *c != '\0'; c++) glutBitmapCharacter(font, *c);
}
// Display Function
void Display(void) {
glClearColor(0.3f, 0.5f, 0.9f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Set 3D
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, (int)width, (int)height);
gluPerspective(30, width/height, 0.1, 10000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Set camera
gluLookAt(cam1,27,130, 5,11,0, 0,1,0);
glutPostRedisplay();
// Light and Z-buffer
glPushAttrib(GL_ALL_ATTRIB_BITS);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmb);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiff);
// Draw Map and Car
glPushMatrix();
// load map obj
glPushMatrix();
glTranslatef(x,y,z);
glRotatef(-180, 0.0, 1.0, 0.0);
glmDraw(map, GLM_SMOOTH | GLM_MATERIAL);
glPopMatrix();
// load car obj
glPushMatrix();
glTranslatef(x+carx, y+cary, z+carz);
glRotatef(-180, 0.0, 1.0, 0.0);
glmDraw(car, GLM_SMOOTH | GLM_MATERIAL);
glPopMatrix();
glPopMatrix();
glPopAttrib();
glFlush();
// Set 2D
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,width,height,0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
// Draw text
glPushMatrix();
glColor3f(1, 1, 1);
renderBitmapString(10,20,(void *)font2,"Press 'H' for show/hide help");
glEnd();
glPopMatrix();
// Show help menu
if(h1==true) {
glTranslatef((float)((width-500)/2),(float)(500+((height-500)/2)),0);
glPushMatrix();
glColor3f(1, 1, 1);
glBegin(GL_QUADS);
glVertex3f(0.0f, -500.0f, 0.0f); // The bottom left corner
glVertex3f(0.0f, 0.0f, 0.0f); // The top left corner
glVertex3f(500.0f, 0.0f, 0.0f); // The top right corner
glVertex3f(500.0f, -500.0f, 0.0f); // The bottom right corner
glEnd();
glPopMatrix();
glPushMatrix();
glColor3f(0, 0, 0);
renderBitmapString(130,-440,(void *)font1,"P H Y S X C A R S I M U L A T O R");
renderBitmapString(190,-410,(void *)font2,"HELP MENU:");
renderBitmapString(60,-350,(void *)font2,"'K' = change to left-side camera");
renderBitmapString(60,-320,(void *)font2,"'L' = change to right-side camera");
renderBitmapString(60,-290,(void *)font2,"'ESC' = exit program");
renderBitmapString(60,-50,(void *)font1,"Author: Son Nguyen (NGU0013) Version: 1.0 , 2012");
glEnd();
glPopMatrix();
}
glutSwapBuffers();
}
// Main Function
int main(int argc, char **argv) {
cout << "Loading models ... ";
initModels();
cout << "DONE" << endl;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize((int)width, (int)height);
glutInitWindowPosition(0, 0);
glutCreateWindow("PhysX Car Simulator");
glutFullScreen();
initPhysX();
glutDisplayFunc(Display);
glutKeyboardFunc(Keyboard);
glutKeyboardUpFunc(KeyboardUp);
glutIdleFunc(myIdleFunc);
glutMainLoop();
deinitPhysX();
return 0;
}
[/CODE]

Thanks for help.
0

Share this post


Link to post
Share on other sites
I have bad resize function which is in Display method because I don't know how can I resize 3D and 2D in method outside of Display method :(
0

Share this post


Link to post
Share on other sites
After some googling I found solution:
on keyboard pressed "F":
[CODE]
if(fkey==false) {
fkey=true;
width=1366.0;
height=768.0;
glutFullScreen();
}
else {
fkey=false;
width=800.0;
height=600.0;
glutPositionWindow(0,0);
glutReshapeWindow(800,600);
}
[/CODE]
I have some troubles with reshape function that reshaped fullscreen to window, but instead of size 800x600 was same as fullscreen 1366x768 and when I moved glutPositionWindow before Reshape method it worked :)
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0