zdravim potrebujem pomoc. Nemozem nacitat grafiku zo suboru *.txt, kompilator mi nevypisuje chybu ale po kompilacii mi zobrazi ciernu obrazovku, no bude to asi logicka chyba. Mozno to bude chyba vo funkcii " void SetupWorld() ", asi pri alokovani dynamickeho pola alebo as pri vykreslovani vo fun. "static void draw_objekt_3d()".
tu su tie funkcie.:
Kód:
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <iostream>
#include <stdlib.h>
#include <GL/glew.h>
#include <SDL/SDL.h>
//#include "SDL_opengl.h"
#include "time.h"
#include "math.h"
#include "user_input_enum.h"
#define TRUE 1
#define FALSE 0
#include "setting.h"
bool light;
using namespace std;
int done=0;
int mouse_x,mouse_y;
int user_input[1000];
static float rotation1=0;
static float rotation2=0; //deklaracia pomocnej premennej pre rotaciu
GLfloat yrot; /* Camera rotation variable */
GLfloat xpos, zpos; /* Camera pos variable */
GLfloat walkbias= 0.0f; /* Head-bobbing variables */
GLfloat walkbiasangle= 0.0f;
GLfloat lookupdown= 0.0f;
typedef struct tagVERTEX //nove
{
float x, y, z; /* 3D Coordinates */
float u, v; /* Texture Coordinates */
} VERTEX;
typedef struct tagTRIANGLE //nove
{
VERTEX vertex1[3]; /* Array Of Three Vertices */
} TRIANGLE;
typedef struct tagSECTOR //nove
{
int numTriangles; /* Number Of Triangles In Sector */
TRIANGLE* triangle1; /* Pointer To Array Of Triangles */
} SECTOR;
SECTOR sector1; //nove
-----------------------------------
void readstr( FILE *f, char *string )
{
/* Start A Loop */
do
{
/* Read One Line */
fgets( string, 255, f );
} while ( ( string[0] == '/' ) || ( string[0] == '\n' ) );
return;
}
///////////////////////////////////////////////////////////////////////////////
void SetupWorld()
{
FILE *filein; /* File To Work With */
int numTriangles; /* Number of Triangles */
char oneLine[255]; /* One line from conf file */
float x, y, z, u, v; /* 3d and texture coordinates */
int triLoop; /* Triangle loop variable */
int verLoop; /* Vertex loop variable */
// worldFile = "data\\world.txt";
/* Open Our File */
filein = fopen("data\\world.txt", "rt" );
/* Grab a line from 'filein' */
readstr( filein, oneLine );
/* Read in number of triangle */
sscanf( oneLine, "NUMPOLLIES %d\n", &numTriangles );
/* allocate space for our triangles */
//sector1.triangle1 = new Triangle[numTriangles];
///////////////////////////////////////////////////////////////////////////////////////////////////
sector1.triangle1 = new TRIANGLE[numTriangles];
//delete (sector1.triangle1);
/*
int a;
void* vp=&a;
int * ip=(int*)vp;
ip=static_cast<int*> (vp);
*ip=8;
*/
if ( sector1.triangle1 == NULL )
{
fprintf( stderr, "Could not allocate memory for triangles.\n" );
exit(0);
}
sector1.numTriangles = numTriangles;
/* Get coords for each triangle */
for ( triLoop = 0; triLoop < numTriangles; triLoop++ )
{
for ( verLoop = 0; verLoop < 3; verLoop++ )
{
readstr( filein, oneLine );
sscanf( oneLine, "%f %f %f %f %f\n", &x, &y, &z, &u, &v );
sector1.triangle1[triLoop].vertex1[verLoop].x = x;
sector1.triangle1[triLoop].vertex1[verLoop].y = y;
sector1.triangle1[triLoop].vertex1[verLoop].z = z;
sector1.triangle1[triLoop].vertex1[verLoop].u = u;
sector1.triangle1[triLoop].vertex1[verLoop].v = v;
// delete [] sector1.triangle1;
}
}
//////////////////////////////////////////////////////////////////////
delete [] sector1.triangle1;
/* Close Our File */
fclose( filein );
return;
.
.
.
alebo
Kód:
#ifndef _draw_object_3d_h_
#define _draw_object_3d_h_
.
.
.
/////////////////////////////////////////////////////
static void draw_objekt_3d()
{
if(user_input[SDLK_RIGHT])
{
yrot -= 1.5f;
}
if(user_input[SDLK_LEFT])
{
yrot += 1.5f;
}
if(user_input[SDLK_UP])
{
/* Move On The X-Plane Based On Player Direction */
xpos -= ( float )sin( yrot * piover180 ) * 0.05f;
/* Move On The Z-Plane Based On Player Direction */
zpos -= ( float )cos( yrot * piover180 ) * 0.05f;
if ( walkbiasangle >= 359.0f )
walkbiasangle = 0.0f;
else
walkbiasangle+= 10;
/* Causes the player to bounce */
walkbias = ( float )sin( walkbiasangle * piover180 ) / 20.0f;
}
if(user_input[SDLK_DOWN])
{
/* Move On The X-Plane Based On Player Direction */
xpos += ( float )sin( yrot * piover180 ) * 0.05f;
/* Move On The Z-Plane Based On Player Direction */
zpos += ( float )cos( yrot * piover180 ) * 0.05f;
if ( walkbiasangle <= 1.0f )
walkbiasangle = 359.0f;
else
walkbiasangle -= 10;
walkbias = ( float )sin( walkbiasangle * piover180 ) / 20.0f;
}
/* Rotate Up And Down To Look Up And Down */
glRotatef( lookupdown, 1.0f, 0.0f , 0.0f );
/* Rotate Depending On Direction Player Is Facing */
glRotatef( sceneroty, 0.0f, 1.0f , 0.0f );
/* Translate The Scene Based On Player Position */
glTranslatef( xtrans, ytrans, ztrans );
//glDisable(GL_TEXTURE_2D);
//glEnable(GL_LIGHTING);
// glEnable(GL_BLEND); // Turn Blending On
// glDisable(GL_DEPTH_TEST); // Turn Depth Testing Off
/* Bottom Left Of The Texture and Quad */
glBindTexture( GL_TEXTURE_2D, texture[2] );
// glTranslatef(pohX,pohY,0.0f);
for ( loop_m = 0; loop_m < sector1.numTriangles; loop_m++ )
{
/* Start Drawing Triangles */
glBegin(GL_TRIANGLES);
/* Normal Pointing Forward */
glNormal3f( 0.0f, 0.0f, 1.0f);
/* X Vertex Of 1st Point */
x_m = sector1.triangle1[loop_m].vertex1[0].x;
/* Y Vertex Of 1st Point */
y_m = sector1.triangle1[loop_m].vertex1[0].y;
/* Z Vertex Of 1st Point */
z_m = sector1.triangle1[loop_m].vertex1[0].z;
/* U Texture Coord Of 1st Point */
u_m = sector1.triangle1[loop_m].vertex1[0].u;
/* V Texture Coord Of 1st Point */
v_m = sector1.triangle1[loop_m].vertex1[0].v;
/* Set The TexCoord And Vertice */
glTexCoord2f( u_m, v_m );
glVertex3f( x_m, y_m, z_m );
/* X Vertex Of 2nd Point */
x_m = sector1.triangle1[loop_m].vertex1[1].x;
/* Y Vertex Of 2nd Point */
y_m = sector1.triangle1[loop_m].vertex1[1].y;
/* Z Vertex Of 2nd Point */
z_m = sector1.triangle1[loop_m].vertex1[1].z;
/* U Texture Coord Of 2nd Point */
u_m = sector1.triangle1[loop_m].vertex1[1].u;
/* V Texture Coord Of 2nd Point */
v_m = sector1.triangle1[loop_m].vertex1[1].v;
/* Set The TexCoord And Vertice */
glTexCoord2f( u_m, v_m );
glVertex3f( x_m, y_m, z_m );
/* X Vertex Of 3rd Point */
x_m = sector1.triangle1[loop_m].vertex1[2].x;
/* Y Vertex Of 3rd Point */
y_m = sector1.triangle1[loop_m].vertex1[2].y;
/* Z Vertex Of 3rd Point */
z_m = sector1.triangle1[loop_m].vertex1[2].z;
/* Texture Coord Of 3rd Point */
u_m = sector1.triangle1[loop_m].vertex1[2].u;
/* V Texture Coord Of 3rd Point */
v_m = sector1.triangle1[loop_m].vertex1[2].v;
/* Set The TexCoord And Vertice */
glTexCoord2f( u_m, v_m );
glVertex3f( x_m, y_m, z_m );
glEnd( );
.
.
.
.
}
Dany kod je nepouzitelny, preto tu davam aj cely workspace pre program Eclipse.,
Nie je to link na warez, o je to moje. jj. ""!!!!,
skuste mi pomoct, inak v tom worku je to "openglL10", diik.
PS: nevem ci to je kompilovatelne pod windows, Linux no problem.
link":
Kód:
http://rapidshare.com/files/148569164/eclipse1.zip.html
nemaste to, no WAREZ.