• 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.

Archived

This topic is now archived and is closed to further replies.

taxman

help w/ crash since glut 3.7

1 post in this topic

I made the jump to glut 3.7 so I could try out their new fullscreen easy switching. Problem is that now I get a crash after everytime it executes, and after that crash I have to reboot before I can try again. This is my frist day trying opengl (yes I''ve been up for a lot of hours) Any general advice and extra help would be greatly appreciated as well.
  
#include <GL/glut.h>
#include <GL/gl.h>
#include <stdlib.h>
#include <math.h>
#include <iostream.h>
#include "image.h"


int width=500;
int height=500;

GLfloat spin = 0.0;
int prevmx = 0;
int prevmy = 0;
GLfloat increment = 0.05f;

const float piover180 = 0.0174532925f;
float heading;
float xpos;
float zpos;
int cheat=0;

GLfloat	yrot;				// Y Rotation

GLfloat walkbounce = 0;
GLfloat walkbounceangle = 0;
GLfloat lookupdown = 180.0f;

int minvert = -1;	//mouse inverts if you hit I

int freemouse=0;

GLuint texture[1];

#define MAZE_HEIGHT (16)
#define MAZE_WIDTH  (16)
char *mazedata[MAZE_HEIGHT] = {
		"****************",
        "*X      *      *",
        "* * *** * *    *",
        "* **  * ** * * *",
        "*     *      * *",
        "********** *** *",
        "*           *  *",
        "* ***** *** ****",
        "* *   *   *    *",
        "*   *******    *",
        "* *   *   *  * *",
        "* ***** **** * *",
        "*     *      * *",
        "** ** **** *** *",
        "*   * *    *   *",
        "************* **",
};

void LoadGLTextures();



//strings in 3d position

void draw_string_bitmap(void *font, const char* string, int x, int y) 
{
	glRasterPos3f(x+0.3, 0.4f, y+0.5);
	while (*string)
		glutBitmapCharacter(font, *string++);
}

void buildLists(){
//stored list of things to always be drawn that never change

#define MAZE_LIST 1
	glNewList(MAZE_LIST, GL_COMPILE);
	glPushAttrib(GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT);
	glLineWidth(2.0);

	for(int y=0;y<MAZE_HEIGHT;y++) {
		for(int x=0;x<MAZE_WIDTH;x++) {
			if(mazedata[x][y]==''*'') {
				glColor3f(0.5,0.5,0.5);
				glBegin(GL_QUAD_STRIP);
					glVertex3f( x  ,   0, y);
					glVertex3f( x  ,   1, y);
					glVertex3f( x+1,   0, y);
					glVertex3f( x+1,   1, y);
					glVertex3f( x+1,   0, y+1);
					glVertex3f( x+1,   1, y+1);
					glVertex3f( x  ,   0, y+1);
					glVertex3f( x  ,   1, y+1);
					glVertex3f( x  ,   0, y);
					glVertex3f( x  ,   1, y);
				glEnd();
			}
			else if(mazedata[x][y]==''X''){
				//cout << x << " " << y << endl;

				xpos=-x-0.5;
				zpos=-y-0.5;
				//cout << xpos << " " << zpos << endl;

				glColor3f(0.75,0.5,0.5);
				glBegin(GL_QUADS);
				//	glTexCoord2f(0.0 , 0.0);

					glVertex3f( x  ,   1, y);
				//	glTexCoord2f(0.0 , 1.0);

					glVertex3f( x+1,   1, y);
				//	glTexCoord2f(1.0 , 1.0);

					glVertex3f( x+1,   1, y+1);
				//	glTexCoord2f(1.0 , 0.0);

					glVertex3f( x,     1, y+1);
				glEnd();
			}
			else if(mazedata[x][y]=='' ''){
				glColor3f(0.5,0.5,0.75);
			//	glEnable(GL_TEXTURE_2D);

				glBindTexture(GL_TEXTURE_2D, texture[0]); 
				glBegin(GL_QUADS);
					glTexCoord2f(0.0 , 0.0);
					glVertex3f( x  ,   1, y);
					glTexCoord2f(0.0 , 1.0);
					glVertex3f( x+1,   1, y);
					glTexCoord2f(1.0 , 1.0);
					glVertex3f( x+1,   1, y+1);
					glTexCoord2f(1.0 , 0.0);
					glVertex3f( x,     1, y+1);
				glEnd();
			//	glDisable(GL_TEXTURE_2D);

			}
			else if(mazedata[x][y]==''1''){
				glColor3f(1.0 , 0.0 , 0.0);
				draw_string_bitmap("fixed", "Lost?", x,y);
			}
		}
	}

	glPopAttrib();
	glEndList();
}




void display()
{

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer

	glLoadIdentity();									// Reset The View


	GLfloat ypos = -0.65-walkbounce;
	GLfloat sceneroty = 360.0f - yrot;

	glRotatef(lookupdown,1.0f,0,0);
	glRotatef(sceneroty,0,1.0f,0);
	
	glTranslatef(xpos, ypos+cheat, zpos);

	glCallList(MAZE_LIST);
	glEnable(GL_TEXTURE_2D);
	glutSwapBuffers();

}


void click_mouse(int button, int state, int x, int y)
{
//mouse buttons if state==GLUT_DOWN && button== GLUT_RIGHT_BUTTON...

}

void move_mouse(int x, int y)
{
/*annoying, but works
if(x>width-25 || x<25 || y<25 || y>height-25) 
	if(!freemouse)
		glutWarpPointer(width/2,height/2);

	if(y<prevmy){
		lookupdown += 1.0f * minvert;	
	}
	else if(y>prevmy){
		lookupdown -= 1.0f * minvert;
	}

	if(x<prevmx){
		heading -= 2.0f;
		yrot = heading;	
	}
	else if(x>prevmx){
		heading += 2.0f;
		yrot = heading;	
	}

	prevmy=y;
	prevmx=x;

	display(); //force redraw
*/
}

void nav_kbd(unsigned char key, int x, int y)
{

	if(key == ''w'')
	{
			xpos -= sin(heading*piover180)*0.1;
			zpos -= cos(heading*piover180)*0.1;
			if (walkbounceangle >= 359.0f) 
				walkbounceangle = 0.0f;
			else 
				walkbounceangle += 10;
			walkbounce = sin(walkbounceangle*piover180)/7.5;		
	}
	if(key == ''s'')
	{
			xpos += sin(heading*piover180)*0.1f;
			zpos += cos(heading*piover180)*0.1f;
			if (walkbounceangle <= 1.0f) 
				walkbounceangle = 359.0f;
			else 
				walkbounceangle-= 10;
			walkbounce = sin(walkbounceangle*piover180)/7.5;		
	}
	if(key == ''a'')
	{
			heading -= 2.5f;	
			yrot = heading;
	}
	if(key == ''d'')
	{
			heading += 2.5f;
			yrot = heading;			
	}

	if(key == ''i'')
	{
			minvert*=-1;			
	}
	if(key == ''t'')
	{
		exit(0);	
	}
	if(key == ''c'')
	{
		++cheat;			
	}
	if(key == ''v'')
	{
		--cheat;			
	}

	glutPostRedisplay();
}

void idle(){
	glutPostRedisplay() ;
}

void reshape(int w, int h){
	
	glViewport(0,0,(GLsizei)w,(GLsizei)h) ;
	glMatrixMode(GL_PROJECTION) ;
	glLoadIdentity() ;
	gluPerspective(60.0,(GLfloat)w/(GLfloat)h,0.1,10.0) ;
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glEnable(GL_DEPTH_TEST);
	LoadGLTextures();
	buildLists();
	glutPostRedisplay();

}

void LoadGLTextures() {	
    Image *image1;
    
    image1 = (Image *) malloc(sizeof(Image));
    if (image1 == NULL) {
	cout << "Error allocating space for image";
	exit(0);
    }

    if (!ImageLoad("stone.bmp", image1)) {
	exit(1);
    } 

    /* Create Texture	*****************************************/
    glGenTextures(2, &texture[0]);
    glBindTexture(GL_TEXTURE_2D, texture[0]);   /* 2d texture (x and y size)*/

    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); /* scale linearly when image bigger than texture*/
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); /* scale linearly when image smalled than texture*/
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);

    glTexImage2D(GL_TEXTURE_2D, 0, 3, image1->sizeX, image1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image1->data);

	free(image1->data);
	free(image1);

};

void myinit()
{
	//glShadeModel(GL_SMOOTH);

	//glEnable(GL_CULL_FACE);

	glClearColor(0.0, 0.0, 0.0, 0.0);
	glColor3f(1.0, 1.0, 1.0);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();			
	glMatrixMode(GL_MODELVIEW);	
	glLoadIdentity();
	glEnable(GL_DEPTH_TEST);
	LoadGLTextures();
	buildLists();

}

void main(int argc, char **argv)
{

	glutInit(&argc, argv) ;
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) ; 

	glutGameModeString("800x600:16@60") ;
	if (glutGameModeGet(GLUT_GAME_MODE_WIDTH) != -1)  // if the width is different to -1

	{
		myinit();
		glutEnterGameMode();		// enter full screen mode

		glutDisplayFunc(display) ;
		glutReshapeFunc(reshape) ;
		glutIdleFunc(idle) ;
		glutKeyboardFunc(nav_kbd) ;
	}
	else							// print out that this mode is not available

		cout << "Chances are you don''t have glut 3.7 from xmission.com/~nate/glut.html \n";

	glutMainLoop() ;

}


  
0

Share this post


Link to post
Share on other sites
You should create a window with glutCreateWindow() before trying to register callbacks. That''s because callbacks are registered for a specific window (the last created or the one you last glutSetWindow()''ed ). Since you have no window yet...
0

Share this post


Link to post
Share on other sites