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

TerranFury

Help me strangle this bug...

0 posts in this topic

I am trying to triangulate a heightmap in a uniform grid using multiple vertex lists of triangle strips. It was working, but then I tried to make the code better by eliminating my global variables. Now, I'm geting incomprehensible triangle "junk" on the screen (I don't THINK there's a memory leak; otherwise I'd be getting Access Violation errors, wouldn't I?). Most of it is blue and green (my color list only specifies shades of blue and green) but some some is magenta or white (how'd THAT get there?), and when I draw GL_LINE_STRIPs and disable color lists instead of colored GL_TRIANGLE_STRIPs, whole areas of the screen are pure white - filled with lines. I know it's a bit much to ask to post all this code up here, but I, for some reason, just can't catch my mistake. If anyone could help me, I would be very appreciative: To begin, I do the following:
      
terrain = maketerrain(10, 10, 0.75, 1.25)
  
The associated code is below
  
struct terr_struct
{
	GLfloat *** verts;
	GLfloat *** cols;
	unsigned long width;
	unsigned long height;
	unsigned long vert_num;
};
terr_struct terrain;



double cos_interpol(float a, float b, float x)
{
	//Why is this here?  So I can triangulate my mesh

	//in multiple resolutions, eventually


	float ft = x * pi;
	float f = (1 - cos(ft)) * .5;
	
	return  a * (1-f) + b * f;
}



void genmap(unsigned char ** maparry, unsigned long width, unsigned long height)
{
	for(int y = 0; y < height + 3; y++)
	{
		for(int x = 0; x < width + 3; x++)
		{
			maparry[x][y] = rand() % 256;
		}
	}
}

float map(double x, double y, unsigned char ** maparry)
{
	float ans;
	float x1, x2;
	float xfactor = (double)x - (double)((long)x);
	float yfactor = (double)y - (double)((long)y);

	x1 = cos_interpol(maparry[(long)x][(long)y], maparry[(long)x][(long)y + 1], xfactor);
	x1 = cos_interpol(maparry[(long)x + 1][(long)y], maparry[(long)x +1][(long)y + 1], xfactor);
	ans = x1 * (1 - yfactor) + x2 * yfactor;

	return (float)ans / (float)255;
}


void makecols(unsigned char ** maparry, GLfloat *** a_cols)
{
	char a = 0;

	for(int y = 0; y < 10 - 1; y++)
	{
		for(int x = 0; x < 20; x++)
		{
			if(x%2 == 0){a=0;}else{a=1;}

			//Dumb place-filler function that looks sort of like

			//blue water and green hills.

			a_cols[y][x][0] = 0;
			a_cols[y][x][1] = pow((map(x/2, y + a, maparry))/(float)2, 2) * 2;//a_verts[y][x][1];

			a_cols[y][x][2] = pow((1 - map(x/2, y + a, maparry))/(float)2, 2) * 2;//a_verts[y][x][1];

		}
	}
}

unsigned long makegrid(float tilesize, float yscale, unsigned char ** maparry, GLfloat *** a_verts, unsigned long width, unsigned long height)
{
	unsigned long vnum = 0;
	unsigned long total_vnum = 0;

	for(long y = 0; y < height - 1; y++)
	{
		for(long x = 0; x < width; x++)
		{
			a_verts[y][vnum][0] = (x - (float)(width / (float)2)) * (float)tilesize;
			a_verts[y][vnum][2] = (y - (float)(height / (float)2)) * (float)tilesize;
			a_verts[y][vnum][1] = map(x, y, maparry) * yscale;
			vnum++;
			total_vnum++;

			a_verts[y][vnum][0] = (x - (float)(width / (float)2)) * (float)tilesize;
			a_verts[y][vnum][2] = ((y + 1) - (float)(height / (float)2)) * (float)tilesize;
			a_verts[y][vnum][1] = map(x, (y+1), maparry) * yscale;
			vnum++;
			total_vnum++;
		}
		vnum = 0;
	}

	return total_vnum;
}

terr_struct maketerrain(unsigned long width, unsigned long height, float tilesize, float yscale)
{
	unsigned char ** terr_map;
	GLfloat *** verts;
	GLfloat *** cols;
	terr_struct ret_val;
	
	terr_map = new unsigned char * [width + 3];
	for(unsigned long i = 0; i < width + 3; i++)
	{
		terr_map[i] = new unsigned char[height + 3];
	}

	verts = new GLfloat ** [height - 1];
	for(unsigned long y = 0; y < height - 1; y++)
	{
		verts[y] = new GLfloat * [width * 2];
		for(unsigned long x = 0; x < width * 2; x++)
		{
			verts[y][x] = new GLfloat[3];
		}
	}

	cols = new GLfloat ** [height - 1];
	for(y = 0; y < height - 1; y++)
	{
		cols[y] = new GLfloat * [width * 2];
		for(unsigned long x = 0; x < width * 2; x++)
		{
			cols[y][x] = new GLfloat[3];
		}
	}

	genmap(terr_map, width, height);
	ret_val.vert_num = makegrid(tilesize, yscale, terr_map, verts, width, height);
	makecols(terr_map, cols);

	for(i = 0; i < height + 3; i++)
	{
		delete [] terr_map[i];
	}
	delete [] terr_map;

	ret_val.cols = cols;
	ret_val.verts = verts;
	ret_val.width = width;
	ret_val.height = height;

	return ret_val;
}
  
Then I try to draw it each frame as follows:
  
for(unsigned long i = 0; i < terrain.height - 1; i++)
{
		glVertexPointer(3 , GL_FLOAT, 0, terrain.verts[i] );
		glColorPointer(3, GL_FLOAT, 0, terrain.cols[i]); 
		glDrawArrays(GL_TRIANGLE_STRIP, 0, terrain.vert_num);
}
  
So there you have it. Thanks in advance for any help. Edited by - TerranFury on August 8, 2001 10:59:36 PM
0

Share this post


Link to post
Share on other sites