I don't know where to put this questions so I'll ask here since I'm using SDL+OpenGL to render. I could compile this app using devcpp with full optomization but I just got myself MSVc++6 and it won't compile on "release' mode. Only debug. C++
Release Build:
--------------------Configuration: torus - Win32 Release--------------------
Compiling...
torus.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\torus\torus.cpp(106) : warning C4305: 'argument' : truncation from 'const double' to 'float'
C:\Program Files\Microsoft Visual Studio\MyProjects\torus\torus.cpp(106) : warning C4305: 'argument' : truncation from 'const double' to 'float'
C:\Program Files\Microsoft Visual Studio\MyProjects\torus\torus.cpp(152) : warning C4101: 'znear' : unreferenced local variable
C:\Program Files\Microsoft Visual Studio\MyProjects\torus\torus.cpp(152) : warning C4101: 'aspect' : unreferenced local variable
C:\Program Files\Microsoft Visual Studio\MyProjects\torus\torus.cpp(152) : warning C4101: 'zfar' : unreferenced local variable
C:\Program Files\Microsoft Visual Studio\MyProjects\torus\torus.cpp(152) : warning C4101: 'FOVy' : unreferenced local variable
C:\Program Files\Microsoft Visual Studio\MyProjects\torus\torus.cpp(257) : warning C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data
C:\Program Files\Microsoft Visual Studio\MyProjects\torus\torus.cpp(258) : warning C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data
C:\Program Files\Microsoft Visual Studio\MyProjects\torus\torus.cpp(260) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
C:\Program Files\Microsoft Visual Studio\MyProjects\torus\torus.cpp(261) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
C:\Program Files\Microsoft Visual Studio\MyProjects\torus\torus.cpp(262) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
Linking...
msvcrt.lib(MSVCRT.dll) : error LNK2005: _exit already defined in LIBC.lib(crt0dat.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _strncpy already defined in LIBC.lib(strncpy.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: __isctype already defined in LIBC.lib(isctype.obj)
LIBC.lib(crt0init.obj) : warning LNK4098: defaultlib "msvcrt.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
Release/torus.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
torus.exe - 4 error(s), 12 warning(s)
Here's the DEBUG build:
Deleting intermediate files and output files for project 'torus - Win32 Debug'.
--------------------Configuration: torus - Win32 Debug--------------------
Compiling...
torus.cpp
c:\program files\microsoft visual studio\myprojects\torus\torus.cpp(106) : warning C4305: 'argument' : truncation from 'const double' to 'float'
c:\program files\microsoft visual studio\myprojects\torus\torus.cpp(106) : warning C4305: 'argument' : truncation from 'const double' to 'float'
c:\program files\microsoft visual studio\myprojects\torus\torus.cpp(152) : warning C4101: 'znear' : unreferenced local variable
c:\program files\microsoft visual studio\myprojects\torus\torus.cpp(152) : warning C4101: 'aspect' : unreferenced local variable
c:\program files\microsoft visual studio\myprojects\torus\torus.cpp(152) : warning C4101: 'zfar' : unreferenced local variable
c:\program files\microsoft visual studio\myprojects\torus\torus.cpp(152) : warning C4101: 'FOVy' : unreferenced local variable
c:\program files\microsoft visual studio\myprojects\torus\torus.cpp(257) : warning C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data
c:\program files\microsoft visual studio\myprojects\torus\torus.cpp(258) : warning C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data
c:\program files\microsoft visual studio\myprojects\torus\torus.cpp(260) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
c:\program files\microsoft visual studio\myprojects\torus\torus.cpp(261) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
c:\program files\microsoft visual studio\myprojects\torus\torus.cpp(262) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
Linking...
torus.exe - 0 error(s), 11 warning(s)
Here's the source: C++
/* Testing compile in VC++ 6
Relsoft 2004
Rel.Betterwebber.com
Bug : can't compile in "Release" mode only "Debug"
*/
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <string.h>
#include <sdl/SDL.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <math.h>
struct vector
{
float x;
float y;
float z;
};
struct point3d
{
float x;
float y;
float z;
float r;
float g;
float b;
int color;
};
struct poly
{
int p1;
int p2;
int p3;
float u1;
float v1;
float u2;
float v2;
float u3;
float v3;
int color;
int idx;
};
#define PI = 3.141593
#define TOR_NUM_RINGS 35
#define TOR_NUM_BANDS 28
#define TOR_RING_RAD 1.20 * 1
#define TOR_BAND_RAD 0.30 * 1
#define TOR_MAX_POINTS TOR_NUM_RINGS * TOR_NUM_BANDS
#define SCR_WIDTH 640
#define SCR_HEIGHT 480
#define SCR_BPP 16
//Macros
#define rgb(r, g, b) (r) << 16 | (g) << 8 | (b)
#define relmin(x, y) ( (x) < (y) ? (x) : (y) )
void Init_SDL_GL(int width, int height, int bpp);
void Init_GL(int width, int height);
void Render_Scene(point3d *model, poly *modeltri,
int max3dpoint, int tor_max_poly);
int Get_Max_Poly(int rings, int bands);
void Load_Torus(point3d *model, int rings, int bands,
float ringradius, float bandradius);
void Set_Torus_Faces(poly *tri, int rings, int bands);
/* The screen surface */
SDL_Surface *screen = NULL;
GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f }; // Ambient Light Values
GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f }; // Diffuse Light Values
GLfloat LightPosition[]= { 0.0f, 0.0f, 2.0f, 1.0f }; // Light Position
int main (int argc, char *argv[])
{
int done;
static point3d *torus;
int max3dpoint = TOR_NUM_RINGS * TOR_NUM_BANDS ;
if (!(torus = new point3d[max3dpoint]))
exit(1);
int maxpoly = Get_Max_Poly(TOR_NUM_RINGS, TOR_NUM_BANDS);
static poly *torpoly;
if (!(torpoly = new poly[maxpoly]))
exit (1);
Load_Torus (torus, TOR_NUM_RINGS, TOR_NUM_BANDS,
TOR_RING_RAD, TOR_BAND_RAD);
Set_Torus_Faces(torpoly, TOR_NUM_RINGS, TOR_NUM_BANDS);
Init_SDL_GL(SCR_WIDTH, SCR_HEIGHT, SCR_BPP);
Init_GL(SCR_WIDTH, SCR_HEIGHT);
done = 0;
while (!done)
{
SDL_Event event;
/* Check for events */
while (SDL_PollEvent (&event))
{
switch (event.type)
{
case SDL_KEYDOWN:
if ( event.key.keysym.sym == SDLK_ESCAPE )
{
done = 1;
break;
}
case SDL_QUIT:
done = 1;
break;
default:
break;
}
}
/* Draw to screen */
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Render_Scene (torus, torpoly, max3dpoint, maxpoly);
SDL_GL_SwapBuffers();
SDL_PumpEvents();
}
SDL_Quit();
return 0;
}
void Init_SDL_GL(int width, int height, int bpp)
{
int SDL_flags;
float FOVy, aspect, znear, zfar;
SDL_flags = SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_OPENGL;
//SDL_flags |= SDL_FULLSCREEN;
/* Initialize SDL */
if (SDL_Init (SDL_INIT_VIDEO) < 0)
{
exit (1);
}
atexit (SDL_Quit);
screen = SDL_SetVideoMode (width, height, bpp, SDL_flags);
if (screen == NULL)
{
exit (2);
}
SDL_WM_SetCaption ("SDL+GL Test", NULL);
}
void Init_GL(int width, int height)
{
glViewport (0, 0, width, height);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
float FOVy = (float)80/2.0f;
float aspect = (float)width / (float)height;
float znear = 5.0f;
float zfar = 1000.0f;
gluPerspective (FOVy, aspect, znear, zfar);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity();
glShadeModel (GL_SMOOTH);
glClearColor (0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth (1.0f);
glEnable (GL_DEPTH_TEST);
glDepthFunc (GL_LEQUAL);
glEnable (GL_COLOR_MATERIAL);
glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
/*glColor4f(1.0f,1.0f,1.0f,0.0f); // Full Brightness, 0% Alpha ( NEW )
glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Blending Function For Translucency
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);*/
}
void Render_Scene(point3d *model, poly *modeltri,
int max3dpoint, int tor_max_poly)
{
static float tortheta = 0.00f;
//torus
glPushMatrix();
glLoadIdentity();
glTranslatef (0.0f, 0.0f, -10.0f);
//glTranslatef (200.0f, 200.0f, -256.0f);
glScalef (2.5f, 2.5f, 2.5f);
glRotatef (tortheta, 1.0f, 0.0f, 0.0f);
glRotatef (tortheta, 0.0f, 0.0f, 1.0f);
glRotatef (tortheta, 0.0f, 1.0f, 0.0f);
glBegin (GL_TRIANGLES);
for (int i = 0; i < tor_max_poly; i++)
{
glColor3fv (&model[modeltri.p1].r);
glVertex3fv (&model[modeltri.p1].x);
glColor3fv (&model[modeltri.p2].r);
glVertex3fv (&model[modeltri.p2].x);
glColor3fv (&model[modeltri.p3].r);
glVertex3fv (&model[modeltri.p3].x);
}
glEnd();
glPopMatrix();
tortheta += 1.0f;
glFlush();
}
void Load_Torus(point3d *model, int rings, int bands,
float ringradius, float bandradius)
{
float a1 = 2 * 3.141593f / (float)rings;
float a2 = 2 * 3.141593f / (float)bands;
int i = 0;
for (int s2 = 0; s2 < bands; s2++)
{
for (int s1 = 0; s1 < rings; s1++)
{
float x1 = cos(s1 * a1) * ringradius;
float y1 = sin(s1 * a1) * ringradius;
model.x = x1 + cos(s1 * a1) * cos(s2 * a2) * bandradius;
model.y = y1 + sin(s1 * a1) * cos(s2 * a2) * bandradius;
model.z = sin(s2 * a2) * bandradius;
model.r = (float)rand() / (float)RAND_MAX;
model.g = (float)rand() / (float)RAND_MAX;
model.b = (float)rand() / (float)RAND_MAX;
i++;
}
}
}
int Get_Max_Poly(int rings, int bands)
{
int i = 0;
int maxtri = 0;
for (int s1 = (bands - 1); s1 >= 0; s1--)
{
for (int s2 = (rings - 1); s2 >= 0; s2--)
{
i++;
maxtri++;
i++;
maxtri++;
}
}
return maxtri;
}
void Set_Torus_Faces(poly *tri, int rings, int bands)
{
int maxpoint = rings * bands;
int i = 0;
int r, g, b;
r = 64;
g = 32;
b = 16;
for (int s1 = (bands - 1); s1 >= 0; s1--)
{
for (int s2 = (rings - 1); s2 >= 0; s2--)
{
tri.p3 = (s1 * rings + s2 + rings) % maxpoint;
tri.p2 = s1 * rings + (s2 + 1) % rings;
tri.p1 = s1 * rings + s2;
tri.color = rgb(r,g,b);
tri.idx = i;
i++;
tri.p3 = (s1 * rings + s2 + rings) % maxpoint;
tri.p2 = (s1 * rings + (s2 + 1) % rings + rings) % maxpoint;
tri.p1 = s1 * rings + (s2 + 1) % rings;
tri.color =rgb(r,g,b);
tri.idx = i;
i++;
}
}
}