Jump to content
  • Advertisement
Sign in to follow this  
YamiTenshi

Foggy problem

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

Okay, a little problem here, and probably just another of my stupid mistakes, but after about three hours of searching it's getting pretty annoying, and I really can't figure out what I'm doing wrong. I'm following the fog tutorial by NeHe (tutorial 18 IIRC), with some minor modifications, but the start and end depth I use for the fog seem to have no influence at all: as soon as I enable the fog, the whole window turns black, save for the text in the top-left corner. I've tried every value within the perspective's range, and no results. Source:
/***************************************************************************
 *   Copyright (C) 2008 by Nash van Gool   *
 *   yamitenshi@dazjorz.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/


#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <iostream>
#include <stdlib.h>
#include "SDL.h"
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glx.h>
#include "pi.h"
#include <math.h>
#include <stdarg.h>
#include <string.h>

typedef struct { GLfloat x, y, z; } coord;

SDL_Surface *screen;
bool done = false;
bool light = false;
bool blend = false;
bool active = true;
bool paused = false;
bool fog = false;
GLuint texture[1];
GLuint font;
float xrot = 0;
float yrot = 0;
float xrotspd;
float yrotspd;
float z = 10.0f;

GLfloat lightAmbient[] = { 0.5f, 0.5f, 0.5f, 1.0f };
GLfloat lightDiffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat lightPosition[] = { -1.0f, 1.0f, 2.0f, 1.0f };
GLfloat fogColor[] = { 0.0f, 0.0f, 0.0f, 1.0f };

void initGL();
void drawGLScene();
void loadTextures();
void handleKeyPress(SDL_keysym *keysym);
void initCoordinates();
void createFont();
void killFont();
void Quit(int returnvalue);
void glPrint(const char *fmt, ...);

coord center;
coord top [10];
coord mid [10];
coord bottom;

void Quit(int returnvalue)
{
	glDeleteTextures(1, &texture[0]);
	killFont();
	SDL_Quit();
	exit(returnvalue);
}

void createFont()
{
	Display *dpy;
	XFontStruct *fontInfo;
	
	font = glGenLists(96);
	
	dpy = XOpenDisplay(NULL);
	
	fontInfo = XLoadQueryFont(dpy, "fixed");
	
	if(fontInfo == NULL)
	{
		std::cerr << "Something is wrong. No X font available." << std::endl;
		Quit(1);
	}
	
	glXUseXFont(fontInfo->fid, 32, 96, font);
	
	XFreeFont(dpy, fontInfo);
	XCloseDisplay(dpy);
}

void killFont()
{
	glDeleteLists(font, 96);
}

void glPrint(const char *fmt, ...)
{
	char text[256];
	va_list ap;
	
	if(fmt == NULL)
	{
		return;
	}
	
	va_start(ap, fmt);
		vsprintf(text, fmt, ap);
	va_end(ap);
	
	glPushAttrib(GL_LIST_BIT);
	
	glListBase(font - 33);
	
	glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
	
	glPopAttrib();
}

void initGL()
{
	glShadeModel(GL_SMOOTH);
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	glClearDepth(1.0f);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	glEnable(GL_TEXTURE_2D);
	
	glLightfv(GL_LIGHT1, GL_AMBIENT, lightAmbient);
	glLightfv(GL_LIGHT1, GL_DIFFUSE, lightDiffuse);
	glLightfv(GL_LIGHT1, GL_POSITION, lightPosition);
	glEnable(GL_LIGHT1);
	
	glViewport(0, 0, 480, 640);
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0f, (GLfloat)480 / (GLfloat)640, 0.1f, 100.0f);
	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glBlendFunc(GL_SRC_ALPHA, GL_ONE);
	
	createFont();
	loadTextures();
	
	glFogi(GL_FOG_MODE, GL_EXP);
	glFogfv(GL_FOG_COLOR, fogColor);
	glFogf(GL_FOG_DENSITY, 0.35f);
	glHint(GL_FOG_HINT, GL_DONT_CARE);
	glFogf(GL_FOG_START, z);
	glFogf(GL_FOG_END, z + 10.0f);
}

void drawGLScene()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
	
	if(light)
	{
		glDisable(GL_LIGHTING);
	}
	if(fog)
	{
		glDisable(GL_FOG);
	}
	
	glDisable(GL_TEXTURE_2D);
	glTranslatef(0.0f, 0.0f, -1.0f);
	glColor3f(1.0f, 1.0f, 1.0f);
	glRasterPos2f(-0.29f, 0.36f);
	glPrint("X Rotation: %7.2f", xrot);
	glRasterPos2f(-0.29f, 0.34f);
	glPrint("Y Rotation: %7.2f", yrot);
	glRasterPos2f(-0.29f, 0.32f);
	glPrint("Z value: %7.0f", z);
	glLoadIdentity();
	glEnable(GL_TEXTURE_2D);
	
	if(light)
	{
		glEnable(GL_LIGHTING);
	}
	if(fog)
	{
		glEnable(GL_FOG);
	}
	
	glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
	glTranslatef(0.0f, 0.0f, -12.0f);
	glRotatef(xrot, 1.0f, 0.0f, 0.0f);
	glRotatef(yrot, 0.0f, 1.0f, 0.0f);
		
	glBindTexture(GL_TEXTURE_2D, texture[0]);
	
	glBegin(GL_TRIANGLES);
		glNormal3f(cos(0.0 * TWOPI), 1.0f, -sin(0.0 * TWOPI));
		glTexCoord2f(0.5f, 1.0f); glVertex3f(top[0].x, top[0].y, top[0].z);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(mid[9].x, mid[9].y, mid[9].z);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(mid[0].x, mid[0].y, mid[0].z);
		
		glNormal3f(cos(0.1 * TWOPI), 1.0f, -sin(0.1 * TWOPI));
		glTexCoord2f(0.5f, 1.0f); glVertex3f(top[1].x, top[1].y, top[1].z);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(mid[0].x, mid[0].y, mid[0].z);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(mid[1].x, mid[1].y, mid[1].z);
		
		glNormal3f(cos(0.2 * TWOPI), 1.0f, -sin(0.2 * TWOPI));
		glTexCoord2f(0.5f, 1.0f); glVertex3f(top[2].x, top[2].y, top[2].z);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(mid[1].x, mid[1].y, mid[1].z);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(mid[2].x, mid[2].y, mid[2].z);
		
		glNormal3f(cos(0.3 * TWOPI), 1.0f, -sin(0.3 * TWOPI));
		glTexCoord2f(0.5f, 1.0f); glVertex3f(top[3].x, top[3].y, top[3].z);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(mid[2].x, mid[2].y, mid[2].z);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(mid[3].x, mid[3].y, mid[3].z);
		
		glNormal3f(cos(0.4 * TWOPI), 1.0f, -sin(0.4 * TWOPI));
		glTexCoord2f(0.5f, 1.0f); glVertex3f(top[4].x, top[4].y, top[4].z);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(mid[3].x, mid[3].y, mid[3].z);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(mid[4].x, mid[4].y, mid[4].z);
		
		glNormal3f(cos(0.5 * TWOPI), 1.0f, -sin(0.5 * TWOPI));
		glTexCoord2f(0.5f, 1.0f); glVertex3f(top[5].x, top[5].y, top[5].z);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(mid[4].x, mid[4].y, mid[4].z);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(mid[5].x, mid[5].y, mid[5].z);
		
		glNormal3f(cos(0.6 * TWOPI), 1.0f, -sin(0.6 * TWOPI));
		glTexCoord2f(0.5f, 1.0f); glVertex3f(top[6].x, top[6].y, top[6].z);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(mid[5].x, mid[5].y, mid[5].z);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(mid[6].x, mid[6].y, mid[6].z);
		
		glNormal3f(cos(0.7 * TWOPI), 1.0f, -sin(0.7 * TWOPI));
		glTexCoord2f(0.5f, 1.0f); glVertex3f(top[7].x, top[7].y, top[7].z);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(mid[6].x, mid[6].y, mid[6].z);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(mid[7].x, mid[7].y, mid[7].z);
		
		glNormal3f(cos(0.8 * TWOPI), 1.0f, -sin(0.8 * TWOPI));
		glTexCoord2f(0.5f, 1.0f); glVertex3f(top[8].x, top[8].y, top[8].z);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(mid[7].x, mid[7].y, mid[7].z);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(mid[8].x, mid[8].y, mid[8].z);
		
		glNormal3f(cos(0.9 * TWOPI), 1.0f, -sin(0.9 * TWOPI));
		glTexCoord2f(0.5f, 1.0f); glVertex3f(top[9].x, top[9].y, top[9].z);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(mid[8].x, mid[8].y, mid[8].z);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(mid[9].x, mid[9].y, mid[9].z);
		
		glNormal3f(cos(0.95 * TWOPI), 1.0f, -sin(0.05 * TWOPI));
		glTexCoord2f(0.5f, 0.0f); glVertex3f(mid[9].x, mid[9].y, mid[9].z);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(top[9].x, top[9].y, top[9].z);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(top[0].x, top[0].y, top[0].z);
		
		glNormal3f(cos(0.05 * TWOPI), 1.0f, -sin(0.15 * TWOPI));
		glTexCoord2f(0.5f, 0.0f); glVertex3f(mid[0].x, mid[0].y, mid[0].z);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(top[0].x, top[0].y, top[0].z);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(top[1].x, top[1].y, top[1].z);
		
		glNormal3f(cos(0.15 * TWOPI), 1.0f, -sin(0.25 * TWOPI));
		glTexCoord2f(0.5f, 0.0f); glVertex3f(mid[1].x, mid[1].y, mid[1].z);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(top[1].x, top[1].y, top[1].z);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(top[2].x, top[2].y, top[2].z);
		
		glNormal3f(cos(0.25 * TWOPI), 1.0f, -sin(0.35 * TWOPI));
		glTexCoord2f(0.5f, 0.0f); glVertex3f(mid[2].x, mid[2].y, mid[2].z);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(top[2].x, top[2].y, top[2].z);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(top[3].x, top[3].y, top[3].z);
		
		glNormal3f(cos(0.35 * TWOPI), 1.0f, -sin(0.45 * TWOPI));
		glTexCoord2f(0.5f, 0.0f); glVertex3f(mid[3].x, mid[3].y, mid[3].z);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(top[3].x, top[3].y, top[3].z);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(top[4].x, top[4].y, top[4].z);
		
		glNormal3f(cos(0.45 * TWOPI), 1.0f, -sin(0.55 * TWOPI));
		glTexCoord2f(0.5f, 0.0f); glVertex3f(mid[4].x, mid[4].y, mid[4].z);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(top[4].x, top[4].y, top[4].z);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(top[5].x, top[5].y, top[5].z);
		
		glNormal3f(cos(0.55 * TWOPI), 1.0f, -sin(0.65 * TWOPI));
		glTexCoord2f(0.5f, 0.0f); glVertex3f(mid[5].x, mid[5].y, mid[5].z);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(top[5].x, top[5].y, top[5].z);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(top[6].x, top[6].y, top[6].z);
		
		glNormal3f(cos(0.65 * TWOPI), 1.0f, -sin(0.75 * TWOPI));
		glTexCoord2f(0.5f, 0.0f); glVertex3f(mid[6].x, mid[6].y, mid[6].z);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(top[6].x, top[6].y, top[6].z);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(top[7].x, top[7].y, top[7].z);
		
		glNormal3f(cos(0.75 * TWOPI), 1.0f, -sin(0.85 * TWOPI));
		glTexCoord2f(0.5f, 0.0f); glVertex3f(mid[7].x, mid[7].y, mid[7].z);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(top[7].x, top[7].y, top[7].z);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(top[8].x, top[8].y, top[8].z);
		
		glNormal3f(cos(0.85 * TWOPI), 1.0f, -sin(0.95 * TWOPI));
		glTexCoord2f(0.5f, 0.0f); glVertex3f(mid[8].x, mid[8].y, mid[8].z);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(top[8].x, top[8].y, top[8].z);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(top[9].x, top[9].y, top[9].z);
		
		glNormal3f(cos(0.05 * TWOPI), -0.5f, -sin(0.05 * TWOPI));
		glTexCoord2f(0.5f, 0.0f); glVertex3f(bottom.x, bottom.y, bottom.z);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(mid[0].x, mid[0].y, mid[0].z);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(mid[1].x, mid[1].y, mid[1].z);
		
		glNormal3f(cos(0.15 * TWOPI), -0.5f, -sin(0.15 * TWOPI));
		glTexCoord2f(0.5f, 0.0f); glVertex3f(bottom.x, bottom.y, bottom.z);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(mid[1].x, mid[1].y, mid[1].z);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(mid[2].x, mid[2].y, mid[2].z);
		
		glNormal3f(cos(0.25 * TWOPI), -0.5f, -sin(0.25 * TWOPI));
		glTexCoord2f(0.5f, 0.0f); glVertex3f(bottom.x, bottom.y, bottom.z);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(mid[2].x, mid[2].y, mid[2].z);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(mid[3].x, mid[3].y, mid[3].z);
		
		glNormal3f(cos(0.35 * TWOPI), -0.5f, -sin(0.35 * TWOPI));
		glTexCoord2f(0.5f, 0.0f); glVertex3f(bottom.x, bottom.y, bottom.z);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(mid[3].x, mid[3].y, mid[3].z);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(mid[4].x, mid[4].y, mid[4].z);
		
		glNormal3f(cos(0.45 * TWOPI), -0.5f, -sin(0.45 * TWOPI));
		glTexCoord2f(0.5f, 0.0f); glVertex3f(bottom.x, bottom.y, bottom.z);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(mid[4].x, mid[4].y, mid[4].z);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(mid[5].x, mid[5].y, mid[5].z);
		
		glNormal3f(cos(0.55 * TWOPI), -0.5f, -sin(0.55 * TWOPI));
		glTexCoord2f(0.5f, 0.0f); glVertex3f(bottom.x, bottom.y, bottom.z);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(mid[5].x, mid[5].y, mid[5].z);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(mid[6].x, mid[6].y, mid[6].z);
		
		glNormal3f(cos(0.65 * TWOPI), -0.5f, -sin(0.65 * TWOPI));
		glTexCoord2f(0.5f, 0.0f); glVertex3f(bottom.x, bottom.y, bottom.z);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(mid[6].x, mid[6].y, mid[6].z);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(mid[7].x, mid[7].y, mid[7].z);
		
		glNormal3f(cos(0.75 * TWOPI), -0.5f, -sin(0.75 * TWOPI));
		glTexCoord2f(0.5f, 0.0f); glVertex3f(bottom.x, bottom.y, bottom.z);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(mid[7].x, mid[7].y, mid[7].z);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(mid[8].x, mid[8].y, mid[8].z);
		
		glNormal3f(cos(0.85 * TWOPI), -0.5f, -sin(0.85 * TWOPI));
		glTexCoord2f(0.5f, 0.0f); glVertex3f(bottom.x, bottom.y, bottom.z);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(mid[8].x, mid[8].y, mid[8].z);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(mid[9].x, mid[9].y, mid[9].z);
		
		glNormal3f(cos(0.95 * TWOPI), -0.5f, -sin(0.95 * TWOPI));
		glTexCoord2f(0.5f, 0.0f); glVertex3f(bottom.x, bottom.y, bottom.z);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(mid[9].x, mid[9].y, mid[9].z);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(mid[0].x, mid[0].y, mid[0].z);
		
		glNormal3f(0.0f, 1.0f, 0.0f);
		glTexCoord2f(0.5f, 1.0f); glVertex3f(center.x, center.y, center.z);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(top[0].x, top[0].y, top[0].z);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(top[1].x, top[1].y, top[1].z);
		
		glNormal3f(0.0f, 1.0f, 0.0f);
		glTexCoord2f(0.5f, 1.0f); glVertex3f(center.x, center.y, center.z);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(top[1].x, top[1].y, top[1].z);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(top[2].x, top[2].y, top[2].z);
		
		glNormal3f(0.0f, 1.0f, 0.0f);
		glTexCoord2f(0.5f, 1.0f); glVertex3f(center.x, center.y, center.z);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(top[2].x, top[2].y, top[2].z);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(top[3].x, top[3].y, top[3].z);
		
		glNormal3f(0.0f, 1.0f, 0.0f);
		glTexCoord2f(0.5f, 1.0f); glVertex3f(center.x, center.y, center.z);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(top[3].x, top[3].y, top[3].z);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(top[4].x, top[4].y, top[4].z);
		
		glNormal3f(0.0f, 1.0f, 0.0f);
		glTexCoord2f(0.5f, 1.0f); glVertex3f(center.x, center.y, center.z);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(top[4].x, top[4].y, top[4].z);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(top[5].x, top[5].y, top[5].z);
		
		glNormal3f(0.0f, 1.0f, 0.0f);
		glTexCoord2f(0.5f, 1.0f); glVertex3f(center.x, center.y, center.z);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(top[5].x, top[5].y, top[5].z);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(top[6].x, top[6].y, top[6].z);
		
		glNormal3f(0.0f, 1.0f, 0.0f);
		glTexCoord2f(0.5f, 1.0f); glVertex3f(center.x, center.y, center.z);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(top[6].x, top[6].y, top[6].z);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(top[7].x, top[7].y, top[7].z);
		
		glNormal3f(0.0f, 1.0f, 0.0f);
		glTexCoord2f(0.5f, 1.0f); glVertex3f(center.x, center.y, center.z);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(top[7].x, top[7].y, top[7].z);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(top[8].x, top[8].y, top[8].z);
		
		glNormal3f(0.0f, 1.0f, 0.0f);
		glTexCoord2f(0.5f, 1.0f); glVertex3f(center.x, center.y, center.z);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(top[8].x, top[8].y, top[8].z);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(top[9].x, top[9].y, top[9].z);
		
		glNormal3f(0.0f, 1.0f, 0.0f);
		glTexCoord2f(0.5f, 1.0f); glVertex3f(center.x, center.y, center.z);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(top[9].x, top[9].y, top[9].z);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(top[0].x, top[0].y, top[0].z);
	glEnd();
	
	/*glBegin( GL_QUADS );
      		glNormal3f( 0.0f, 0.0f, 1.0f );
      		glTexCoord2f( 1.0f, 0.0f ); glVertex3f( -1.0f, -1.0f,  1.0f );
      		glTexCoord2f( 0.0f, 0.0f ); glVertex3f(  1.0f, -1.0f,  1.0f );
      		glTexCoord2f( 0.0f, 1.0f ); glVertex3f(  1.0f,  1.0f,  1.0f );
      		glTexCoord2f( 1.0f, 1.0f ); glVertex3f( -1.0f,  1.0f,  1.0f );

      		glNormal3f( 0.0f, 0.0f, -1.0f);
      		glTexCoord2f( 0.0f, 0.0f ); glVertex3f( -1.0f, -1.0f, -1.0f );
      		glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -1.0f,  1.0f, -1.0f );
      		glTexCoord2f( 1.0f, 1.0f ); glVertex3f(  1.0f,  1.0f, -1.0f );
      		glTexCoord2f( 1.0f, 0.0f ); glVertex3f(  1.0f, -1.0f, -1.0f );

      		glNormal3f( 0.0f, 1.0f, 0.0f );
      		glTexCoord2f( 1.0f, 1.0f ); glVertex3f( -1.0f,  1.0f, -1.0f );
      		glTexCoord2f( 1.0f, 0.0f ); glVertex3f( -1.0f,  1.0f,  1.0f );
      		glTexCoord2f( 0.0f, 0.0f ); glVertex3f(  1.0f,  1.0f,  1.0f );
      		glTexCoord2f( 0.0f, 1.0f ); glVertex3f(  1.0f,  1.0f, -1.0f );

      		glNormal3f( 0.0f, -1.0f, 0.0f );
      		glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -1.0f, -1.0f, -1.0f );
      		glTexCoord2f( 1.0f, 1.0f ); glVertex3f(  1.0f, -1.0f, -1.0f );
      		glTexCoord2f( 1.0f, 0.0f ); glVertex3f(  1.0f, -1.0f,  1.0f );
      		glTexCoord2f( 0.0f, 0.0f ); glVertex3f( -1.0f, -1.0f,  1.0f );

      		glNormal3f( 1.0f, 0.0f, 0.0f);
      		glTexCoord2f( 0.0f, 0.0f ); glVertex3f( 1.0f, -1.0f, -1.0f );
      		glTexCoord2f( 0.0f, 1.0f ); glVertex3f( 1.0f,  1.0f, -1.0f );
      		glTexCoord2f( 1.0f, 1.0f ); glVertex3f( 1.0f,  1.0f,  1.0f );
      		glTexCoord2f( 1.0f, 0.0f ); glVertex3f( 1.0f, -1.0f,  1.0f );

      		glNormal3f( -1.0f, 0.0f, 0.0f );
      		glTexCoord2f( 1.0f, 0.0f ); glVertex3f( -1.0f, -1.0f, -1.0f );
      		glTexCoord2f( 0.0f, 0.0f ); glVertex3f( -1.0f, -1.0f,  1.0f );
      		glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -1.0f,  1.0f,  1.0f );
      		glTexCoord2f( 1.0f, 1.0f ); glVertex3f( -1.0f,  1.0f, -1.0f );
    	glEnd();*/
	
	SDL_GL_SwapBuffers();
}

void loadTextures()
{
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	
	SDL_Surface *image = NULL;
	
	image = SDL_LoadBMP("Images/AmethystTexture.bmp");
	std::cout << "Image width: " << image->w << std::endl;
	std::cout << "Image height: " << image->h << std::endl;
	
	glGenTextures( 3, &texture[0] );
	glBindTexture( GL_TEXTURE_2D, texture[0] );
	glTexImage2D( GL_TEXTURE_2D, 0, 3, image->w, image->h, 0, GL_BGR, GL_UNSIGNED_BYTE, image->pixels );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
	
	SDL_FreeSurface(image);
}

void handleKeyPress(SDL_keysym *keysym)
{
	switch(keysym->sym)
	{
		case SDLK_q:
			done = true;
		break;
		case SDLK_b:
			blend = !blend;
			if(blend)
			{
				glEnable(GL_BLEND);
				glDisable(GL_DEPTH_TEST);
			}
			else
			{
				glEnable(GL_DEPTH_TEST);
				glDisable(GL_BLEND);
			}
		break;
		case SDLK_l:
			light = !light;
			if(light)
			{
				glEnable(GL_LIGHTING);
			}
			else
			{
				glDisable(GL_LIGHTING);
			}
		break;
		case SDLK_UP:
			xrotspd += 0.2;
		break;
		case SDLK_DOWN:
			xrotspd -= 0.2;
		break;
		case SDLK_LEFT:
			yrotspd -= 0.2;
		break;
		case SDLK_RIGHT:
			yrotspd += 0.2;
		break;
		case SDLK_p:
			paused = !paused;
		break;
		case SDLK_f:
			fog = !fog;
			if(fog)
			{
				glEnable(GL_FOG);
			}
			else
			{
				glDisable(GL_FOG);
			}
		break;
		case SDLK_PAGEDOWN:
			z -= 1.0;
			glFogf(GL_FOG_START, z);
			glFogf(GL_FOG_END, z + 20.0f);
		break;
		case SDLK_PAGEUP:
			z += 1.0;
			glFogf(GL_FOG_START, z);
			glFogf(GL_FOG_END, z + 20.0f);
		break;
		default:
		break;
	}
}

void initCoordinates()
{
	center.x = 0.0f;
	center.y = 1.0f;
	center.z = 0.0f;
	bottom.x = 0.0f;
	bottom.y = -2.0f;
	bottom.z = 0.0f;
	
	std::cout << "Pi: " << PI << std::endl;
	std::cout << "2Pi: " << TWOPI << std::endl;
	
	for(int c = 0; c < 10; c++)
	{
		std::cout << "Index: " << c << std::endl;
		top[c].x = cos(((c / 10.0) * TWOPI));
		top[c].y = 1.0f;
		top[c].z = -sin((c / 10.0) * TWOPI);
		std::cout << "Top coordinates: " << top[c].x << "," << top[c].y << "," << top[c].z << std::endl;
		std::cout << "Mid Z: " << -sin((c+0.5)/10.0 * TWOPI) << std::endl;
		mid[c].x = 2 * cos((c+0.5)/10.0 * TWOPI);
		mid[c].y = 0.0f;
		mid[c].z = -2 * sin((c+0.5)/10.0 * TWOPI);
		std::cout << "Mid coordinates: " << mid[c].x << "," << mid[c].y << "," << mid[c].z << std::endl;
	}
}
	

int main(int argc, char **argv)
{
	initCoordinates();
	
	SDL_Init(SDL_INIT_EVERYTHING);
	
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
	
	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
	
	screen = SDL_SetVideoMode(480, 640, 32, SDL_OPENGL);
	
	SDL_WM_SetCaption("SDL/OpenGL learning program", NULL);
	
	initGL();
	
	SDL_Event event;
	
	while(!done)
	{
		while(SDL_PollEvent(&event))
		{
			switch(event.type)
			{
				case SDL_KEYDOWN:
					handleKeyPress(&event.key.keysym);
				break;
				case SDL_QUIT:
					done = true;
				break;
				case SDL_ACTIVEEVENT:
					if(event.active.gain == 0 && event.active.state == SDL_APPACTIVE)
					{
						active = false;
					}
					else
					{
						active = true;
					}
				break;
				default:
				break;
			}
		}
		if(active && !paused)
		{
			drawGLScene();
			xrot += xrotspd;
			yrot += yrotspd;
		}
	}
	
	Quit(0);
	
	return 0;
}

[Edited by - YamiTenshi on July 22, 2008 11:32:32 AM]

Share this post


Link to post
Share on other sites
Advertisement
The GL_EXP (aswell as GL_EXP2) fog mode use the GL_FOG_DENSITY parameters to determine the fog. The GL_FOG_START and GL_FOG_END parameters are only used for GL_LINEAR fog.

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!