Jump to content

  • Log In with Google      Sign In   
  • Create Account

WiredCat

Member Since 09 Apr 2011
Offline Last Active Today, 04:29 AM

#5188001 Ray plane intersection problem (need verification to the code)

Posted by WiredCat on 19 October 2014 - 09:40 AM

pls buckeye dont eat me lol :P ok ill debug it




#5186692 Drawing a cricle on the plane

Posted by WiredCat on 13 October 2014 - 07:10 AM

SOLVED        SOLVED        SOLVED      SOLVED

 

 

 

 

 

So i have a plane that has a normal n and distance d (normal normalzied)

 

 

i want to draw a circle on it (set some vertices there on the surface)

 

my code looks like this:

determine what direction face (plane) is facing (x or y or z)

 

go through a loop



if (ShockSurfH.algined == 2) { //Y algin so XZ calculus
t1.y = 0;
t1.x = cos(angle*imopi)*(radius-1.0f);
t1.z = sin(angle*imopi)*(radius-1.0f);

t2.y = 0;
t2.x = cos(angle*imopi)*radius;
t2.z = sin(angle*imopi)*radius;

t3.y = 0;
t3.x = cos(angle2*imopi)*radius;
t3.z = sin(angle2*imopi)*radius;

t4.y = 0;
t4.x = cos(angle2*imopi)*(radius-1.0f);
t4.z = sin(angle2*imopi)*(radius-1.0f);

							 }


shockwaveH[i*4+0] = pos+ ( nH * (t1*nH));
shockwaveH[i*4+1] = pos+ ( nH * (t2*nH));
shockwaveH[i*4+2] = pos+ ( nH * (t3*nH));
shockwaveH[i*4+3] = pos+ ( nH * (t4*nH));

i set circle verts on the 'axis' and then project it onto the plane (the 2nd code) however the bigger slope of the plane circle starts to look like an ellipse.

 

How to draw a normal circle?




#5185527 Dropping a not guided bomb

Posted by WiredCat on 07 October 2014 - 08:04 AM

 

Just a comment, but your weight-force looks suspicious as it appears to be based on position (and you don't mention what "Q") is. If you're trying to account for the slight change of gravity due to height, you should base it only on height, not position.



float Q = eGForce * Weight; // gravity force val  eGForce is 9.81 gravity const     Q euals to m * g //in school they tought me that Q = mg 
(maybe you name it somehow differently)

float squareSpeed = VectorLength(vel); //speed squared ;p

t3dpoint WeightForce = Normalize(-pos) * Q; //since i have almost round globe (not just flat ground with heightmap) 
i Normalize reversed position to obtain a gravity direction vector and multiple it by weight force

t3dpoint DragForce = Normalize(-vel) * (DragCoeff * ((1.250 * squareSpeed)/2.0f) * 0.760f); bla bla bla 0.768 is an area for mk84 ;] and 1.250 is air dens 
(here constant but i have a function for determining the proper airdens)

t3dpoint Acceleration = (WeightForce + DragForce) / Weight; yep still no stabilizators, but it hink they will make bomb go further (checked it by shooting 
arrows with bow ;])

pos = pos + (vel * dt);
vel = vel + (Acceleration * dt); //where dt is time between frames

btw thanks for your replies i will iterate towards ground




#5184121 Problem with positioning an object after no collision :) sounds strange?:P

Posted by WiredCat on 30 September 2014 - 01:44 PM

Hi, i have a problem with calculating position of a tank that its position is calculated from 4 points (see image below there are 4 spheres on the corners of tank hull - red green white and blue)

 

tankf.jpg

 

 

 

So i do following steps:

 

First i calculate forces that are acting on the tank (in this example tank is dropped from 20 meters above the surface), i simplified the formula so force acting on the tank is gravity (weight) only. It should fall to the point on the surface this big red sphere ;]

 

Then after setting new position of a tank i check whenever there was a collision with the surface[ from tank old position to the new one) and if there was i set the tank to the proper position. BUT problem occurs when theres no collision at all

 

let me start from begin:

 

calculate forces acting on tank

for each collision sphere (white,red,green,blue):

check collision (from old position to the new position - new pos, is a pos where we want to go with the tank) if there was no collision return that point where we want to go (new pos)









fl = col->SPHERE_INTERSECT_POLYGON(col_front_left,col_front_left + movement_ray,2.0f,sector,facei,rfl); <-- last value is the returned point
fr = col->SPHERE_INTERSECT_POLYGON(col_front_right,col_front_right + movement_ray,2.0f,sector,facei,rfr);

rl = col->SPHERE_INTERSECT_POLYGON(col_rear_left,col_rear_left + movement_ray,2.0f,sector,facei,rrl);
rr = col->SPHERE_INTERSECT_POLYGON(col_rear_right,col_rear_right + movement_ray,2.0f,sector,facei,rrr);

col_front_left, col_front_right, col_rear_left, col_rear_right are positions of these collision spheres. the return point of collision or no collision is

rfl for front left , rfr for front right, rrl for rear left, rrr for rear right

 

fl,fr,rl,rr are bools to help me determinate where collision occured.

 

then i calculate the actual pitch and roll of the tank, and the new roll and pitch after collision(or no collision)

 

then i subtract them to see the difference (and then i can rotate tank by this angle)

 

a(anglename) stands for actual(anglename)         n(anglename) stands for new(anglename)









t3dpoint aroll  = ( (col_front_left - col_front_right) + (col_rear_left - col_rear_right) ) /2.0f;

t3dpoint apitch = ( (col_front_left - col_rear_left) + (col_front_right - col_rear_right) ) /2.0f;

t3dpoint nroll 	= ( (rfl - rfr) + (rrl - rrr) ) / 2.0f;

t3dpoint npitch = ( (rfl - rrl) + (rfr - rrr) ) / 2.0f;

so now we are here since tank position and rotation is represented by 4 points (these collision spheres)

i calculate the position like

 

pos = (rfl+rfr+rrl+rrr) / 4.0f; (add all sphere positions  and then divide it by the amount of spheres) and this is the main line causing problems, whenever i want to go down it goes infront...

 

heres the full code:











void __fastcall CheckForCollision()
{
int facei = ReturnFaceIndex(oldc);

t3dpoint movement_ray = vectorAB(oldc,pos); //oldc is a point before movement, pos is a point where we want to go (after movement).

t3dpoint rfl, rfr, rrl, rrr;
bool fl,fr,rl,rr;

rfl = col_front_left;
rfr = col_front_right;

rrl = col_rear_left;
rrr = col_rear_right;

     // &PS, //
fl = col->SPHERE_INTERSECT_POLYGON(col_front_left,col_front_left + movement_ray,2.0f,sector,facei,rfl);
fr = col->SPHERE_INTERSECT_POLYGON(col_front_right,col_front_right + movement_ray,2.0f,sector,facei,rfr);

rl = col->SPHERE_INTERSECT_POLYGON(col_rear_left,col_rear_left + movement_ray,2.0f,sector,facei,rrl);
rr = col->SPHERE_INTERSECT_POLYGON(col_rear_right,col_rear_right + movement_ray,2.0f,sector,facei,rrr);



t3dpoint aroll  = ( (col_front_left - col_front_right) + (col_rear_left - col_rear_right) ) /2.0f;

t3dpoint apitch = ( (col_front_left - col_rear_left) + (col_front_right - col_rear_right) ) /2.0f;

t3dpoint nroll 	= ( (rfl - rfr) + (rrl - rrr) ) / 2.0f;

t3dpoint npitch = ( (rfl - rrl) + (rfr - rrr) ) / 2.0f;


//. u = v - n * dot(n, v)
//
// cross(n, cross(v, n))

t3dpoint A,B, n;

A =  vectorAB(sector->VBO_V[sector->VBO_BE[facei].INDEX_START],sector->VBO_V[sector->VBO_BE[facei].INDEX_START+1]);

B =  vectorAB(sector->VBO_V[sector->VBO_BE[facei].INDEX_START],
sector->VBO_V[sector->VBO_BE[facei].INDEX_START+3]);
n = vectorcross(A,B);

t3dpoint proj_surfacev_apitch = n * (apitch*n);
t3dpoint proj_surfacev_npitch = vectorcross(n, vectorcross(npitch,n));

t3dpoint proj_surfacev_aroll = vectorcross(n, vectorcross(aroll,n));
t3dpoint proj_surfacev_nroll = vectorcross(n, vectorcross(nroll,n));

float pitcha = AngleBetweenVectors(proj_surfacev_apitch, apitch);
float rolla = AngleBetweenVectors(proj_surfacev_aroll, aroll);
float pitchn = AngleBetweenVectors(proj_surfacev_npitch, npitch);
float rolln = AngleBetweenVectors(proj_surfacev_nroll, nroll);

float res_pitch = pitchn - pitcha;
float res_roll = rolln - rolla;


hull.rotation.pitch( cos(res_pitch), sin(res_pitch) );
hull.rotation.DoRotation();

hull.rotation.roll( cos(res_roll), sin(res_roll) );
hull.rotation.DoRotation();



pos = (rfl+rfr+rrl+rrr) / 4.0f;

}


any suggestions? i think the code is fine, maybe someone else will tell me that,  it should work but somehow it isn'teverything btween las sphere_intersect_polygon and pos = (xx) / 4.0f is irrevelant to the topic.

 

 

so the code that is responsible for this is like:



void __fastcall CheckForCollision()
{
int facei = ReturnFaceIndex(oldc);

t3dpoint movement_ray = vectorAB(oldc,pos); //oldc is a point before movement, pos is a point where we want to go (after movement).

t3dpoint rfl, rfr, rrl, rrr;
bool fl,fr,rl,rr;

rfl = col_front_left;
rfr = col_front_right;

rrl = col_rear_left;
rrr = col_rear_right;

     // &PS, //
fl = col->SPHERE_INTERSECT_POLYGON(col_front_left,col_front_left + movement_ray,2.0f,sector,facei,rfl);
fr = col->SPHERE_INTERSECT_POLYGON(col_front_right,col_front_right + movement_ray,2.0f,sector,facei,rfr);

rl = col->SPHERE_INTERSECT_POLYGON(col_rear_left,col_rear_left + movement_ray,2.0f,sector,facei,rrl);
rr = col->SPHERE_INTERSECT_POLYGON(col_rear_right,col_rear_right + movement_ray,2.0f,sector,facei,rrr);



pos = (rfl+rfr+rrl+rrr) / 4.0f;

}

maybe il post a vid what i get:

 

 




#5183545 OpenGL rotation matrix, [math] rotates in different direction

Posted by WiredCat on 28 September 2014 - 02:59 PM

First of all i would like you to see this:

tank01.jpg

 

 

 

 

Image shows a tank (not rotated, static) with 4 collision spheres (white, red, green, blue) 

 

 

/ note: three lines what you see (white,red,green) show the positive side of an axis, so for red its +x, for green its +y and for white its +z,

 

 

My problem is whenever i try to rotate a tank spheres are rotated backwards. like on this video:

 

 

To rotate a tank i use exactly the same rotation matrix i use to rotate these spheres.

 

 

 

now to explain it more deeply: sphere base position (in relation to unrotated tank) is calculated like this:

 

 

front_left sphere which is white (span_dist, 0, front_dist) [xyz]

front_right (red) (-span_dist, 0, front_dist) [xyz]

 

 

rear_left (green) (span_dist, 0, -front_dist)

rear_right (blue) (-span_dist, 0, -front_dist)

 

 

 

 

i draw the tank like this:





glPushMatrix();
glLoadIdentity();

gluLookAt(eyepos.x,eyepos.y,eyepos.z,lookat.x,lookat.y,lookat.z,up.x,up.y,up.z);

glTranslatef(pos.x,pos.y,pos.z);
glMultMatrixf(hull.rotation.AIR_MATRIX);
 
						hull.model->DrawSimpleModel();

glPopMatrix(); 

hull.rotation.AIR_MATRIX <- this is my rotation matrix (it only has rotation data, - no translation and scale data)

 

 

now i calculate spheres positions like:



float rotm[16];    int i;
for (i=0; i<16;i++) rotm[i] = hull.rotation.AIR_MATRIX[i];

col_front_left = front_left * rotm;
col_front_left = col_front_left + pos;

col_front_right = front_right * rotm;
col_front_right = col_front_right + pos;

col_rear_left = rear_left * rotm;
col_rear_left = col_rear_left + pos;

col_rear_right = rear_right * rotm;
col_rear_right = col_rear_right + pos;

where rotm is a copied hull.rotation.AIR_MATRIX (ofc same values)

a code for multiplying a vertex by a matrix is:



	  t3dpoint operator*(const float in[16]) const
		{     //since its an opengl engine i use this order
		//note that i do not add translation data and do not use scaling
			return t3dpoint(
in[0]*x+in[1]*y+in[2]*z,

in[4]*x+in[5]*y+in[6]*z,

in[8]*x+in[9]*y+in[10]*z);
		}

No i should say something about how do i calculate rotation matrix:

lets say i have three vectors front, right and up vector

 

 

i rotate them by calling pitch, yaw, roll funcitons

and then i build a matrix like this:



			AIR_MATRIX[0] = rr.x; //right
			AIR_MATRIX[1] = rr.y;
			AIR_MATRIX[2] = rr.z;
			AIR_MATRIX[3] = 0.0f;
			AIR_MATRIX[4] = ru.x; //up
			AIR_MATRIX[5] = ru.y;
			AIR_MATRIX[6] = ru.z;
			AIR_MATRIX[7] = 0.0f;
			AIR_MATRIX[8]  = -rf.x; //front
			AIR_MATRIX[9]  = -rf.y;
			AIR_MATRIX[10] = -rf.z;
			AIR_MATRIX[11] = 0.0f;
			AIR_MATRIX[12] =  0.0f;  //point
			AIR_MATRIX[13] =  0.0f;
			AIR_MATRIX[14] =  0.0f;
			AIR_MATRIX[15] = 1.0f;

Hopefully its enough info for someone that can help me ;x

 

oh i forgot to add that whenever i try to pitch the rotation matrix (opengl model draws properly) but i get stranger spheres pos.




#5180818 Simulation of drag in flightsims

Posted by WiredCat on 16 September 2014 - 02:59 PM

sorry i have so little knowledge about flight dynamics but i saw you are talking about torque, i have a different view

float elevationangle = ELEVATOR_LEFT->GetAngle(); //result is percentage of elevation //*17.5 is the max degree that elevator can reach

float elevator_drag_force = 0.90f *  ((dens * squareSpeed )/ 2.0f) * Abs(elevationangle) * 2.0f*13.2040f;
float leverlen = 8.50f;
float alphaangularity =	 (dt*((leverlen * elevator_drag_force) * sin( (elevationangle*(17.50f+ 90.0f) )*imopi) ) )/ (mass * leverlen*leverlen);// elevator_drag_force*elevator_drag_force);
float angvel = alphaangularity*dt;



#5172305 Triangle vectors on the circle

Posted by WiredCat on 08 August 2014 - 10:11 AM

circle2.jpg
 

 

 

 

ofc every blue line is angled at 30 degrees. geez i forgot to draw a bottom line of that triangle (that with blue lines since its a cut triangle) so it looks that angles are from circle itself to segment.

 

 

I could build up a matrix where red line unit vec is front z+ is up vector and crossproduct of these two is right vec then i could just yaw it. But i am looking for easier solution

 

 

 

 

just was looking at this and you are right alvaro  making average of these two red lines and making a full trianglei can rotate this avg red line by 30 degs, thanks

 

 

 

OK I will gladly post a solution

 

 Graphics::TBitmap * bmp =      new               Graphics::TBitmap;

bmp->PixelFormat = pf24bit;

bmp->Width  = 1000;

bmp->Height = 1000;

 

int bmpcx = bmp->Width / 2;

int bmpcy = bmp->Height / 2;

 

long double angle = 0.0;

long double scale = 60.0;

                           //cm

long double CircleRadius = 6.0*scale;// 6 * 60 = 360 pixels of radius / diameter 720 pixels

 

long double x;

long double y;

 

long double numofteeth = 16;

 

long double circumreference = 2.0 * pild * CircleRadius;

 

long double teethwidth = circumreference / numofteeth;

long double teethheight = 1.0 * scale; //1 cm height

 

int i;

for (angle=0; angle <360; angle= angle + 0.1)

{

x = CircleRadius*cosl(angle*imopild);

y = CircleRadius*sinl(angle*imopild);

 

    bmp->Canvas->Pixels[bmpcx+int(x)][bmpcy+int(y)] = clBlack;

}

 

  int reach = int(numofteeth);

long double tmp = 0;

long double angler1 = 0;

long double angler2 = 0;

long double vecx;

long double vecy;

 

long double avecx;

long double avecy;

 

long double bvecx;

long double bvecy;

 

 

TPoint A,B,C;

 

t3dpoint vec; vec.z = 0.0;

t3dpoint vecb; vecb.z = 0.0;

for (i=0; i < reach; i++)

{

angler1 = 360.0 * ( tmp / circumreference );

angler2 = 360.0 * ( (tmp+teethwidth) / circumreference );

tmp = tmp + teethwidth;

angle = (angler1 + angler2) / 2.0;

 

//lets say add 30 degs to it so triangle will have 60 30 30

 

        vecx = CircleRadius * cosl((angle)*imopild);

        vecy = CircleRadius * sinl((angle)*imopild);

 

 

        vec.x = float(vecx);

        vec.y = float(vecy);

        vec.z = 0.0f;

        vec = Normalize(vec);

 

        vecx = vecx + ( (long double)vec.x * (teethwidth / 2.0) );

        vecy = vecy + ( (long double)vec.y * (teethwidth / 2.0) );

 

        

        avecx = CircleRadius * cosl((angler1)*imopild);

        avecy = CircleRadius * sinl((angler1)*imopild);

 

        bvecx = CircleRadius * cosl((angler2)*imopild);

        bvecy = CircleRadius * sinl((angler2)*imopild);

 

C.x = int(vecx);

C.y = int(vecy);

 

A.x = int(avecx);

A.y = int(avecy);

 

B.x = int(bvecx);

B.y = int(bvecy);

bmp->Canvas->Brush->Style = bsSolid;

bmp->Canvas->Brush->Color = clBlack;

bmp->Canvas->MoveTo(bmpcx+C.x,bmpcy+C.y);

bmp->Canvas->LineTo(bmpcx+A.x,bmpcy+A.y);

 

bmp->Canvas->MoveTo(bmpcx+C.x,bmpcy+C.y);

bmp->Canvas->LineTo(bmpcx+B.x,bmpcy+B.y);

}

bmp->SaveToFile("E:\\FFS_WTF.bmp");

result

 

 

FFS_WTF.jpg




#5171280 Quaternion angle with itself > 0.001

Posted by WiredCat on 03 August 2014 - 11:20 AM

well you could check long double for it

 

 

just make something lie this 

 

 

rewrite dot4 so it will get quaterions (like old did but i will operate on long doubles and will return long double)

ofc function returns long double

then  return  2.0 * acosl( fabsl( DotDouble4( qa, qb ) ) ); }

 

this could use the best precision for floats

 

 

anyway try to rotate something by in ex 90 degrees and try to find that angle.




#5169311 Which is faster/better - glClearColor/glClear or glClearBuffer* ?

Posted by WiredCat on 26 July 2014 - 09:45 AM

glClearCOlor  does not clear anything

 

 

The glClearColor function specifies the red, green, blue, and alpha values used by glClear to clear the color buffers. Values specified by glClearColor are clamped to the range [0,1].

 

https://www.opengl.org/sdk/docs/man/html/glClearColor.xhtml

http://msdn.microsoft.com/en-us/library/windows/desktop/dd318377(v=vs.85).aspx




#5168496 projected lines

Posted by WiredCat on 22 July 2014 - 04:40 PM

omg, that worked! :D




#5167961 Black screen of DOOM!

Posted by WiredCat on 20 July 2014 - 10:34 AM

yes possiblycalling meth0ods between glbegin glend fails everything. if you want to parse model eveytime you call drawing you should do a simplier method, anyway if you dont need such task, load model once and draw it., anyway try to lower z_near value maybe you have set it to 1

 

 

hah but wait.

       glBegin(GL_POLYGON); 
          a=subs[1];
          b=subs[2];
          c=subs[3];
           x=stringToDouble(a);
           y=stringToDouble(b);
           z=stringToDouble(c);
           /****draw 3D vertex*****/
           glVertex3f(x,y,z); 
           glEnd();

What sort of dark magic is this 

 

when you call glBegin(something) glENd it requires at least 1 glvertex3f for a point, 2 glvertex3f for a line, and at least 3 glvertex3f for a poly,

 

i see that you put only one glvertex3f betweeen glbegin(GL_POLYGON); glend(); where you should put at least three of them




#5163629 encounter weird problem when turn on the color blending.

Posted by WiredCat on 29 June 2014 - 08:56 AM

so less details, but anyway try this:

divide whole model to different organs, then try to render every organ where you begin from those that are deep in the body and you end with drawing lungs

 

also glBlendFunc needs to be set properly (and sometimes glColor4f <- alpha value)

 

we also dont know if your textures have alpha channel but i guess they don't)

 

At first you need to draw parts that are not transparent and then you draw transparent organs in proper order.

 

 

if you manage to sort your faces you will get almost the same effect like disabling GL_DEPTH_TEST but you'll see properly displayed model

 

 

this also try to lower z_near value (in glFrustum) 

 

or scale in ex lungs so lungs faces wont touch other organs

 

 

 

=====================

anyway youll have to sort faces or that would be far way faster and easier -organs

 

 

this is what ahppens when you sort faces.

yu.jpg

 

 

 

 

one that i can say is i see there z fighting problem or wrong face order or wrong blending factors




#5161504 directional shadow mapping - simple question

Posted by WiredCat on 19 June 2014 - 09:27 AM

heres an example in delphi (coz thats the simplest code i have) its a projection texture mapping, but when you change initialization to GL_DEPTH_COMPONENT you know something similar to:

 glGenTextures(1,&shadowMapTexture);
 glBindTexture(GL_TEXTURE_2D, shadowMapTexture);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 512, 512, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);

since you should only lookup for opengl calls its really no matter in what language this sample will be:

 

but before showing it to you :P

it uses an old gluLookAt function (you can eaisly glrotate gltranslate scene if you dont want to use this function)

 

this function is used for 2 cases first to draw scene from camera view and then from light view.

(with glulookat its easy to say that light is in pos x,y,z and its pointing in x2,y2,z2 direction or point.

combining znear and zfar too will give you a desired effect.

 

 

 

first of all you need to enable (in openglinitalization)

glEnable(GL_TEXTURE_2D);
glTexGendv(GL_S, GL_OBJECT_PLANE, SPlane);
glTexGendv(GL_T, GL_OBJECT_PLANE, TPlane);
glTexGendv(GL_R, GL_OBJECT_PLANE, RPlane);
glTexGendv(GL_Q, GL_OBJECT_PLANE, QPlane);

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);


glDisable(GL_TEXTURE_2D);

wheres



double *SPlane;
double *TPlane;
double *RPlane;
double *QPlane;


SPlane = new double[4];
SPlane[0] = 1.0;
SPlane[1] = 0.0;
SPlane[2] = 0.0;
SPlane[3] = 0.0;

TPlane = new double[4];
TPlane[0] = 0.0;
TPlane[1] = 1.0;
TPlane[2] = 0.0;
TPlane[3] = 0.0;

RPlane = new double[4];
RPlane[0] = 0.0;
RPlane[1] = 0.0;
RPlane[2] = 1.0;
RPlane[3] = 0.0;

QPlane = new double[4];
QPlane[0] = 0.0;
QPlane[1] = 0.0;
QPlane[2] = 0.0;
QPlane[3] = 1.0;

then you enable blending

draw your scene from eye view

then you change blending func

enable these glplane s t r q

set light viewmatrix

draw the same scene ut w/o textures

 

heres the code:

//------------------------------------------------------------------------
//
// Author      : Jan Horn
// Email       : jhorn@global.co.za
// Website     : http://www.sulaco.co.za
//               http://home.global.co.za/~jhorn
// Date        : 12 March 2002
// Version     : 1.0
// Description : A very basic game engine I put tegether in about 2 hours
//
//------------------------------------------------------------------------
program OpenGLApp;

uses
  Windows,
  Messages,
  OpenGL,
  SysUtils,
  Textures;

const
  WND_TITLE = 'Basic game engine by Jan Horn';
  FPS_TIMER = 1;                     // Timer to calculate FPS
  FPS_INTERVAL = 500;               // Calculate FPS every 1000 ms

type
  TCoord = Record
    X, Y, Z : glFLoat;
  end;
  TFace = Record
    V1, V2, V3, V4 : Integer;
    U, V : glFloat;
    TextureIndex : Integer;
  end;

var
  h_Wnd  : HWND;                     // Global window handle
  h_DC   : HDC;                      // Global device context
  h_RC   : HGLRC;                    // OpenGL rendering context
  keys : Array[0..255] of Boolean;   // Holds keystrokes
  FPSCount : Integer = 0;            // Counter for FPS
  ElapsedTime : Integer;             // Elapsed time between frames
  FrameTime : Integer;

  // Textures
  Texture : Array of glUint;

  // User variables
  TextureCount : Integer;
  VertexCount  : Integer;
  FaceCount    : Integer;
  Vertex : Array of TCoord;
  Face   : Array of TFace;

  X, Z : glFloat;
  HeadMovement, HeadMovAngle : glFloat;
  mpos : TPoint;
  Heading : glFloat;
  Tilt    : glFloat;

  MouseSpeed : Integer = 7;
  MoveSpeed  : glFloat = 0.03;
   Pmv : array[0..15] of single;
    ProjectedTex : glUint;
  WallTex : glUint;
  FloorTex : glUint;
  CubeDL : glUint;
  imopi : single = 3.14/ 180.0;


  MoveTexture : Boolean;
  RoomDL : glUint;
  FloorDL : glUint;
  sphereX, sphereY, sphereZ : glFloat;
  SPlane : array [0..3] of GLfloat = (1, 0, 0, 0);
  TPlane : array [0..3] of GLfloat = (0, 1, 0, 0);
  RPlane : array [0..3] of GLfloat = (0, 0, 1, 0);
  QPlane : array [0..3] of GLfloat = (0, 0, 0, 1);
  ax,ay,az : single;

{$R *.RES}

procedure glBindTexture(target: GLenum; texture: GLuint); stdcall; external opengl32;

{------------------------------------------------------------------}
{  Load the map info from the map.txt files                        }
{------------------------------------------------------------------}
procedure LoadMap;
var F : Textfile;
    Tex : Array of String;
    S : String;
    I, J : Integer;
begin
  AssignFile(F, 'map.txt');
  Reset(F);

  // Load the textures
  Readln(F, TextureCount);
  SetLength(Tex, TextureCount);
  SetLength(Texture, TextureCount);
  for I :=0 to TextureCount-1 do
  begin
    Readln(F, S);
    Tex[i] :=Copy(S, 1, Pos(' ', S)-1);
    S :=Copy(S, Pos(' ', S)+1, length(S));
    LoadTexture(S, Texture[i], FALSE);
  end;

  // Load the vertices
  Readln(F, VertexCount);
  SetLength(Vertex, VertexCount);
  for I :=0 to VertexCount-1 do
    Readln(F, Vertex[i].X, Vertex[i].Y, Vertex[i].Z);

  // Load the faces
  Readln(F, FaceCount);
  SetLength(Face, FaceCount);
  for I :=0 to FaceCount-1 do
  begin
    Readln(F, Face[i].V1, Face[i].V2, Face[i].V3, Face[i].V4, Face[i].U, Face[i].V, S);
    S :=Trim(Copy(S, 1, 12));

    for J :=0 to TextureCount-1 do
      if Tex[J] = S then
        Face[i].TextureIndex :=J;
  end;
  CloseFile(F);
end;


procedure drawscene();
var
i:integer;
begin

//  glRotate(Tilt, 1, 0, 0);
//  glRotate(Heading, 0, 1, 0);
//  glTranslatef(X, -0.5 + HeadMovement, Z);


  For I :=0 to FaceCount-1 do
  with face[i] do
  begin
    glBindTexture(GL_TEXTURE_2D, Texture[TextureIndex]);
    glBegin(GL_QUADS);
      glTexCoord(0, 0);  glVertex3fv(@Vertex[V1-1]);
      glTexCoord(U, 0);  glVertex3fv(@Vertex[V2-1]);
      glTexCoord(U, V);  glVertex3fv(@Vertex[V3-1]);
      glTexCoord(0, V);  glVertex3fv(@Vertex[V4-1]);
    glEnd();
  end;

end;



procedure drawscene2();
var
i:integer;
begin

//  glRotate(-Tilt, 1, 0, 0);
//  glRotate(-Heading, 0, 1, 0);

  For I :=0 to FaceCount-1 do
  with face[i] do
  begin

    glBegin(GL_QUADS);
      glTexCoord(0, 0);  glVertex3fv(@Vertex[V1-1]);
      glTexCoord(U, 0);  glVertex3fv(@Vertex[V2-1]);
      glTexCoord(U, V);  glVertex3fv(@Vertex[V3-1]);
      glTexCoord(0, V);  glVertex3fv(@Vertex[V4-1]);
    glEnd();
  end;



end;
{------------------------------------------------------------------}
{  Function to draw the actual scene                               }
{------------------------------------------------------------------}
procedure glDraw();
var I : Integer;
begin



 glEnable(GL_BLEND);
 glEnable(GL_TEXTURE_2D);

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


glBlendFunc(GL_ONE, GL_ZERO);



glMatrixMode(GL_MODELVIEW);

glLoadIdentity();                                       // Reset The View

ax := 100000.0*(sin((Heading)*imopi)*cos((Tilt)*imopi));
az := 100000.0*(cos((Heading)*imopi)*cos((Tilt)*imopi));
ay := 100000.0*(sin((Tilt)*imopi));
gluLookAt(x,0.2,z,x+ax,
0.2-ay,z-az,0,1,0);

drawscene;


glcolor3f(1,1,1);
  glBlendFunc(GL_DST_COLOR, GL_ONE);
  glBindTexture(GL_TEXTURE_2D, ProjectedTex);




  glEnable(GL_TEXTURE_GEN_S);
  glEnable(GL_TEXTURE_GEN_T);
  glEnable(GL_TEXTURE_GEN_R);
  glEnable(GL_TEXTURE_GEN_Q);




  
  glMatrixMode(GL_TEXTURE);
  glLoadIdentity;
  glTranslatef(0.5, 0.5, 0);
  glScalef(0.5, 0.5, 1);
  gluPerspective(90, 4.0/3.0, 0.1, 100.0);

gluLookAt(2.218,0.3,0.96,
-2.58,0.3,2.87,
0,1,0);//light view matrix set


 glMatrixMode(GL_MODELVIEW);
  glPushMatrix();
drawscene2;
  glPopMatrix();



  glDisable(GL_TEXTURE_GEN_S);
  glDisable(GL_TEXTURE_GEN_T);
  glDisable(GL_TEXTURE_GEN_R);
  glDisable(GL_TEXTURE_GEN_Q);
  glMatrixMode(GL_TEXTURE);
  glLoadIdentity;



 glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);

end;


{------------------------------------------------------------------}
{  Initialise OpenGL                                               }
{------------------------------------------------------------------}
procedure glInit();
begin
  glClearColor(0.0, 0.0, 0.0, 0.0); 	   // Black Background
  glShadeModel(GL_SMOOTH);                 // Enables Smooth Color Shading
  glClearDepth(1.0);                       // Depth Buffer Setup
  glEnable(GL_DEPTH_TEST);                 // Enable Depth Buffer
  glDepthFunc(GL_LEQUAL);		           // The Type Of Depth Test To Do

  glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);   //Realy Nice perspective calculations

  glEnable(GL_TEXTURE_2D);                     // Enable Texture Mapping
  LoadMap;

  Heading :=180;
  X :=1.615;
  Z :=-2.52;



  glEnable(GL_TEXTURE_2D);                     // Enable Texture Mapping
  LoadTexture('biohazard.bmp', ProjectedTex,FALSE);    // Load the Texture
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

  LoadTexture('brick27.bmp', WallTex,FALSE);    // Load the Texture
  LoadTexture('Wood004.bmp', FloorTex,FALSE);    // Load the Texture


glTexGenfv(GL_S, GL_OBJECT_PLANE, @SPlane);
glTexGenfv(GL_T, GL_OBJECT_PLANE, @TPlane);
glTexGenfv(GL_R, GL_OBJECT_PLANE, @RPlane);
glTexGenfv(GL_Q, GL_OBJECT_PLANE, @QPlane);

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);


  
  glDisable(GL_TEXTURE_2D);
end;


{------------------------------------------------------------------}
{  Handle window resize                                            }
{------------------------------------------------------------------}
procedure glResizeWnd(Width, Height : Integer);
begin
  if (Height = 0) then                // prevent divide by zero exception
    Height := 1;
  glViewport(0, 0, Width, Height);    // Set the viewport for the OpenGL window
  glMatrixMode(GL_PROJECTION);        // Change Matrix Mode to Projection
  glLoadIdentity();                   // Reset View
  gluPerspective(90.0, Width/Height, 0.1, 100.0);  // Do the perspective calculations. Last value = max clipping depth

  glMatrixMode(GL_MODELVIEW);         // Return to the modelview matrix
  glLoadIdentity();                   // Reset View
end;


{------------------------------------------------------------------}
{  Processes all the keystrokes                                    }
{------------------------------------------------------------------}
procedure ProcessKeys;
begin
  if Keys[VK_DOWN] then
  begin
    X := X - sin(Heading*pi/180)*FrameTime/600;   // FrameTime/600=movement speed
    Z := Z + cos(Heading*pi/180)*FrameTime/600;   // FrameTime/600=movement speed
    HeadMovAngle :=HeadMovAngle + 5;
    HeadMovement :=0.025*sin(HeadMovAngle*pi/180);
  end;
  if Keys[VK_UP] then
  begin
    X := X + sin(Heading*pi/180)*FrameTime/600;
    Z := Z - cos(Heading*pi/180)*FrameTime/600;
    HeadMovAngle :=HeadMovAngle - 5;
    HeadMovement :=0.025*sin(HeadMovAngle*pi/180);
  end;
  if Keys[VK_RIGHT] then
  begin
    X := X + sin((Heading+90)*pi/180)*FrameTime/900;  // FrameTime/900=movement speed
    Z := Z - cos((Heading+90)*pi/180)*FrameTime/900;  // straffing = 50% slower
  end;
  if Keys[VK_LEFT] then
  begin
    X := X - sin((Heading+90)*pi/180)*FrameTime/900;
    Z := Z + cos((Heading+90)*pi/180)*FrameTime/900;
  end;
end;


{------------------------------------------------------------------}
{  Determines the application’s response to the messages received  }
{------------------------------------------------------------------}
function WndProc(hWnd: HWND; Msg: UINT;  wParam: WPARAM;  lParam: LPARAM): LRESULT; stdcall;
begin
  case (Msg) of
    WM_CREATE:
      begin
        // Insert stuff you want executed when the program starts
      end;
    WM_CLOSE:
      begin
        PostQuitMessage(0);
        Result := 0
      end;
    WM_KEYDOWN:       // Set the pressed key (wparam) to equal true so we can check if its pressed
      begin
        keys[wParam] := True;
        Result := 0;
      end;
    WM_KEYUP:         // Set the released key (wparam) to equal false so we can check if its pressed
      begin
        keys[wParam] := False;
        Result := 0;
      end;
    WM_SIZE:          // Resize the window with the new width and height
      begin
        glResizeWnd(LOWORD(lParam),HIWORD(lParam));
        Result := 0;
      end;
    WM_TIMER :                     // Add code here for all timers to be used.
      begin
        if wParam = FPS_TIMER then
        begin
          FPSCount :=Round(FPSCount * 1000/FPS_INTERVAL);   // calculate to get per Second incase intercal is less or greater than 1 second
          SetWindowText(h_Wnd, PChar(WND_TITLE + '   [' + intToStr(FPSCount) + ' FPS]' + '    '+floattostr(x)+ '   ' + floattostr(z)));
          FPSCount := 0;
          Result := 0;
        end;
      end;
    else
      Result := DefWindowProc(hWnd, Msg, wParam, lParam);    // Default result if nothing happens
  end;
end;


{---------------------------------------------------------------------}
{  Properly destroys the window created at startup (no memory leaks)  }
{---------------------------------------------------------------------}
procedure glKillWnd(Fullscreen : Boolean);
begin
  if Fullscreen then             // Change back to non fullscreen
  begin
    ChangeDisplaySettings(devmode(nil^), 0);
    ShowCursor(True);
  end;

  // Makes current rendering context not current, and releases the device
  // context that is used by the rendering context.
  if (not wglMakeCurrent(h_DC, 0)) then
    MessageBox(0, 'Release of DC and RC failed!', 'Error', MB_OK or MB_ICONERROR);

  // Attempts to delete the rendering context
  if (not wglDeleteContext(h_RC)) then
  begin
    MessageBox(0, 'Release of rendering context failed!', 'Error', MB_OK or MB_ICONERROR);
    h_RC := 0;
  end;

  // Attemps to release the device context
  if ((h_DC > 0) and (ReleaseDC(h_Wnd, h_DC) = 0)) then
  begin
    MessageBox(0, 'Release of device context failed!', 'Error', MB_OK or MB_ICONERROR);
    h_DC := 0;
  end;

  // Attempts to destroy the window
  if ((h_Wnd <> 0) and (not DestroyWindow(h_Wnd))) then
  begin
    MessageBox(0, 'Unable to destroy window!', 'Error', MB_OK or MB_ICONERROR);
    h_Wnd := 0;
  end;

  // Attempts to unregister the window class
  if (not UnRegisterClass('OpenGL', hInstance)) then
  begin
    MessageBox(0, 'Unable to unregister window class!', 'Error', MB_OK or MB_ICONERROR);
    hInstance := 0;
  end;
end;


{--------------------------------------------------------------------}
{  Creates the window and attaches a OpenGL rendering context to it  }
{--------------------------------------------------------------------}
function glCreateWnd(Width, Height : Integer; Fullscreen : Boolean; PixelDepth : Integer) : Boolean;
var
  wndClass : TWndClass;         // Window class
  dwStyle : DWORD;              // Window styles
  dwExStyle : DWORD;            // Extended window styles
  dmScreenSettings : DEVMODE;   // Screen settings (fullscreen, etc...)
  PixelFormat : GLuint;         // Settings for the OpenGL rendering
  h_Instance : HINST;           // Current instance
  pfd : TPIXELFORMATDESCRIPTOR;  // Settings for the OpenGL window
begin
  h_Instance := GetModuleHandle(nil);       //Grab An Instance For Our Window
  ZeroMemory(@wndClass, SizeOf(wndClass));  // Clear the window class structure

  with wndClass do                    // Set up the window class
  begin
    style         := CS_HREDRAW or    // Redraws entire window if length changes
                     CS_VREDRAW or    // Redraws entire window if height changes
                     CS_OWNDC;        // Unique device context for the window
    lpfnWndProc   := @WndProc;        // Set the window procedure to our func WndProc
    hInstance     := h_Instance;
    hCursor       := LoadCursor(0, IDC_ARROW);
    lpszClassName := 'OpenGL';
  end;

  if (RegisterClass(wndClass) = 0) then  // Attemp to register the window class
  begin
    MessageBox(0, 'Failed to register the window class!', 'Error', MB_OK or MB_ICONERROR);
    Result := False;
    Exit
  end;

  // Change to fullscreen if so desired
  if Fullscreen then
  begin
    ZeroMemory(@dmScreenSettings, SizeOf(dmScreenSettings));
    with dmScreenSettings do begin              // Set parameters for the screen setting
      dmSize       := SizeOf(dmScreenSettings);
      dmPelsWidth  := Width;                    // Window width
      dmPelsHeight := Height;                   // Window height
      dmBitsPerPel := PixelDepth;               // Window color depth
      dmFields     := DM_PELSWIDTH or DM_PELSHEIGHT or DM_BITSPERPEL;
    end;

    // Try to change screen mode to fullscreen
    if (ChangeDisplaySettings(dmScreenSettings, CDS_FULLSCREEN) = DISP_CHANGE_FAILED) then
    begin
      MessageBox(0, 'Unable to switch to fullscreen!', 'Error', MB_OK or MB_ICONERROR);
      Fullscreen := False;
    end;
  end;

  // If we are still in fullscreen then
  if (Fullscreen) then
  begin
    dwStyle := WS_POPUP or                // Creates a popup window
               WS_CLIPCHILDREN            // Doesn't draw within child windows
               or WS_CLIPSIBLINGS;        // Doesn't draw within sibling windows
    dwExStyle := WS_EX_APPWINDOW;         // Top level window
    ShowCursor(False);                    // Turn of the cursor (gets in the way)
  end
  else
  begin
    dwStyle := WS_OVERLAPPEDWINDOW or     // Creates an overlapping window
               WS_CLIPCHILDREN or         // Doesn't draw within child windows
               WS_CLIPSIBLINGS;           // Doesn't draw within sibling windows
    dwExStyle := WS_EX_APPWINDOW or       // Top level window
                 WS_EX_WINDOWEDGE;        // Border with a raised edge
    ShowCursor(False);                    // Turn of the cursor (gets in the way)
  end;

  // Attempt to create the actual window
  h_Wnd := CreateWindowEx(dwExStyle,      // Extended window styles
                          'OpenGL',       // Class name
                          WND_TITLE,      // Window title (caption)
                          dwStyle,        // Window styles
                          0, 0,           // Window position
                          Width, Height,  // Size of window
                          0,              // No parent window
                          0,              // No menu
                          h_Instance,     // Instance
                          nil);           // Pass nothing to WM_CREATE
  if h_Wnd = 0 then
  begin
    glKillWnd(Fullscreen);                // Undo all the settings we've changed
    MessageBox(0, 'Unable to create window!', 'Error', MB_OK or MB_ICONERROR);
    Result := False;
    Exit;
  end;

  // Try to get a device context
  h_DC := GetDC(h_Wnd);
  if (h_DC = 0) then
  begin
    glKillWnd(Fullscreen);
    MessageBox(0, 'Unable to get a device context!', 'Error', MB_OK or MB_ICONERROR);
    Result := False;
    Exit;
  end;

  // Settings for the OpenGL window
  with pfd do
  begin
    nSize           := SizeOf(TPIXELFORMATDESCRIPTOR); // Size Of This Pixel Format Descriptor
    nVersion        := 1;                    // The version of this data structure
    dwFlags         := PFD_DRAW_TO_WINDOW    // Buffer supports drawing to window
                       or PFD_SUPPORT_OPENGL // Buffer supports OpenGL drawing
                       or PFD_DOUBLEBUFFER;  // Supports double buffering
    iPixelType      := PFD_TYPE_RGBA;        // RGBA color format
    cColorBits      := PixelDepth;           // OpenGL color depth
    cRedBits        := 0;                    // Number of red bitplanes
    cRedShift       := 0;                    // Shift count for red bitplanes
    cGreenBits      := 0;                    // Number of green bitplanes
    cGreenShift     := 0;                    // Shift count for green bitplanes
    cBlueBits       := 0;                    // Number of blue bitplanes
    cBlueShift      := 0;                    // Shift count for blue bitplanes
    cAlphaBits      := 0;                    // Not supported
    cAlphaShift     := 0;                    // Not supported
    cAccumBits      := 0;                    // No accumulation buffer
    cAccumRedBits   := 0;                    // Number of red bits in a-buffer
    cAccumGreenBits := 0;                    // Number of green bits in a-buffer
    cAccumBlueBits  := 0;                    // Number of blue bits in a-buffer
    cAccumAlphaBits := 0;                    // Number of alpha bits in a-buffer
    cDepthBits      := 16;                   // Specifies the depth of the depth buffer
    cStencilBits    := 0;                    // Turn off stencil buffer
    cAuxBuffers     := 0;                    // Not supported
    iLayerType      := PFD_MAIN_PLANE;       // Ignored
    bReserved       := 0;                    // Number of overlay and underlay planes
    dwLayerMask     := 0;                    // Ignored
    dwVisibleMask   := 0;                    // Transparent color of underlay plane
    dwDamageMask    := 0;                     // Ignored
  end;

  // Attempts to find the pixel format supported by a device context that is the best match to a given pixel format specification.
  PixelFormat := ChoosePixelFormat(h_DC, @pfd);
  if (PixelFormat = 0) then
  begin
    glKillWnd(Fullscreen);
    MessageBox(0, 'Unable to find a suitable pixel format', 'Error', MB_OK or MB_ICONERROR);
    Result := False;
    Exit;
  end;

  // Sets the specified device context's pixel format to the format specified by the PixelFormat.
  if (not SetPixelFormat(h_DC, PixelFormat, @pfd)) then
  begin
    glKillWnd(Fullscreen);
    MessageBox(0, 'Unable to set the pixel format', 'Error', MB_OK or MB_ICONERROR);
    Result := False;
    Exit;
  end;

  // Create a OpenGL rendering context
  h_RC := wglCreateContext(h_DC);
  if (h_RC = 0) then
  begin
    glKillWnd(Fullscreen);
    MessageBox(0, 'Unable to create an OpenGL rendering context', 'Error', MB_OK or MB_ICONERROR);
    Result := False;
    Exit;
  end;

  // Makes the specified OpenGL rendering context the calling thread's current rendering context
  if (not wglMakeCurrent(h_DC, h_RC)) then
  begin
    glKillWnd(Fullscreen);
    MessageBox(0, 'Unable to activate OpenGL rendering context', 'Error', MB_OK or MB_ICONERROR);
    Result := False;
    Exit;
  end;

  // Initializes the timer used to calculate the FPS
  SetTimer(h_Wnd, FPS_TIMER, FPS_INTERVAL, nil);

  // Settings to ensure that the window is the topmost window
  ShowWindow(h_Wnd, SW_SHOW);
  SetForegroundWindow(h_Wnd);
  SetFocus(h_Wnd);

  // Ensure the OpenGL window is resized properly
  glResizeWnd(Width, Height);
  glInit();

  Result := True;
end;


{--------------------------------------------------------------------}
{  Main message loop for the application                             }
{--------------------------------------------------------------------}
function WinMain(hInstance : HINST; hPrevInstance : HINST;
                 lpCmdLine : PChar; nCmdShow : Integer) : Integer; stdcall;
var
  msg : TMsg;
  finished : Boolean;
  DemoStart, LastTime : DWord;
begin
  finished := False;

  // Perform application initialization:
  if not glCreateWnd(800, 600, FALSE, 32) then
  begin
    Result := 0;
    Exit;
  end;

  DemoStart := GetTickCount();            // Get Time when demo started
  SetCursorPos(400,300);

  // Main message loop:
  while not finished do
  begin
    if (PeekMessage(msg, 0, 0, 0, PM_REMOVE)) then // Check if there is a message for this window
    begin
      if (msg.message = WM_QUIT) then     // If WM_QUIT message received then we are done
        finished := True
      else
      begin                               // Else translate and dispatch the message to this window
  	TranslateMessage(msg);
        DispatchMessage(msg);
      end;
    end
    else
    begin
      Inc(FPSCount);                      // Increment FPS Counter

      FrameTime := GetTickCount() - ElapsedTime - DemoStart;
      LastTime :=ElapsedTime;
      ElapsedTime :=GetTickCount() - DemoStart;     // Calculate Elapsed Time
      ElapsedTime :=(LastTime + ElapsedTime) DIV 2; // Average it out for smoother movement

      // use mouse coordinates to calculate heading and tilt and reset mouse.
      if GetForegroundWindow = h_Wnd then
      begin
        GetCursorPos(mpos);
        SetCursorPos(400,300);
        Heading := Heading + (mpos.x - 400)/100 * MouseSpeed;
        Tilt := Tilt - (300 - mpos.y)/100 * MouseSpeed;
        if Tilt > 60 then Tilt :=60;
        if Tilt < -60 then Tilt :=-60;
      end;

      glDraw();                           // Draw the scene
      SwapBuffers(h_DC);                  // Display the scene

      if (keys[VK_ESCAPE]) then           // If user pressed ESC then set finised TRUE
        finished := True
      else
        ProcessKeys;                      // Check for any other key Pressed
    end;
  end;
  glKillWnd(FALSE);
  Result := msg.wParam;
end;


begin
  WinMain( hInstance, hPrevInst, CmdLine, CmdShow );
end.

and heres a result (see that middle and last picture) projected texture -> example above, and when you changed texture to a depth texture you got (last) a shadow (first image is my old notebook bugged graphics card)

 

Untsitled.jpg




#5158796 unresolved external symbol problem

Posted by WiredCat on 06 June 2014 - 03:53 PM

glewinit initializes all extensions defined in glew.h 

 

 

Posted 03 June 2014 - 08:22 PM

WiredCat, on 03 Jun 2014 - 6:37 PM, said:

in header add:
PFNGLMULTIDRAWELEMENTSPROC glMultiDrawElements; //name it whatever you want

and in cpp file: you need to initalize it

Its more than 10000 Lines where should i add it?

 

you should add it after creating opengl context, (usually in glinit function)




#5157860 unresolved external symbol problem

Posted by WiredCat on 03 June 2014 - 10:37 AM

since you have all linked its easy to get it working:

first see this code dont add it to your app

 

 

in glew.h



#define glMultiDrawElements GLEW_GET_FUN(__glewMultiDrawElements)
GLEW_FUN_EXPORT PFNGLMULTIDRAWELEMENTSPROC __glewMultiDrawElements;
typedef void (GLAPIENTRY * PFNGLMULTIDRAWELEMENTSPROC) (GLenum mode, GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount);

so to get it working: (in your app) (ofc add #include glew.h or in my case gl/glew.h)

in header add: 



PFNGLMULTIDRAWELEMENTSPROC  glMultiDrawElements; //name it whatever you want

and in cpp file: you need to initalize it



	glMultiDrawElements = NULL;
	glMultiDrawElements        = (PFNGLMULTIDRAWELEMENTSPROC) wglGetProcAddress("glMultiDrawElements");

be happy its working ;p at least should be

 

if its still NULL then your card  does not support such kind of feature






PARTNERS