Jump to content

opengl not working... help please


Chiblue
 Share

Recommended Posts

I am using pretty much standard open GL functions to allow me to rotate objects... but I do not know what I am doing wrong maybe there is something I need to initialisze first but I am calling my leglDrawImageRect which I have included which in a different project loads the image ang rotates it in a 2d environment... here is the associated code... can someone help??

 

void leglBegin(TCamera camera, float zoom, CullMode cm)
{
   // Setup projetion according to argument
   if (NULL != camera)
   {
       // Save current projection matrix. Then reset
       glMatrixMode(GL_PROJECTION); glPushMatrix(); 
       glLoadIdentity();

       // Calculate the view frustum
       float nearRange, farRange; GetCameraRange(camera, nearRange, farRange);
       float theta = 1.0f / zoom; // tan(45°) = 1.0f
       float aspect = float(BufferWidth(CurrentBuffer()))/BufferHeight(CurrentBuffer());
       glFrustum (-nearRange*theta, nearRange*theta, -nearRange/aspect*theta, nearRange/aspect*theta, nearRange,farRange);

       // Reset transformation
       glMatrixMode(GL_MODELVIEW); glPushMatrix();
       glLoadIdentity();

       // LE uses a differently handed coordinate system than ogl does
       glScalef(1.0f, 1.0f, -1.0f); 

       // Calculate the LookAt vectors (camera direction and up vector)...
       TVec3 from = EntityPosition(camera, true);
       TVec3 to = {0,0,-1}; to = TFormVector(to, camera, NULL); to += from;

       TVec3 up = {0,1,0}; up = TFormVector(up, camera, NULL);

       // Set LookAt 
       gluLookAt(from.X, from.Y, from.Z, to.X, to.Y , to.Z, up.X, up.Y, up.Z);
   }
   else
   {
       glPushMatrix();
       // Set orthographic projection (used for 2D drawing)
       // Get the current viewport/buffer size.
       int vPort[4]; glGetIntegerv(GL_VIEWPORT, vPort); 

       // Set the projection
       gluOrtho2D(0, vPort[2], vPort[3], 0); // like glOrtho(0, vPort[2], vPort[3], 0, -1, 1); 

       // Reset transformation
       glMatrixMode(GL_MODELVIEW); glPushMatrix();
       glLoadIdentity();
   }

   // Setup default drawing settings.
   // Alpha blending.
   glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

   // Backface culling.
   if (CULL_NONE != cm)glEnable(GL_CULL_FACE); 
   if (NULL != camera)glCullFace((CULL_DRAW_CCW == cm) ? GL_BACK : GL_FRONT);
   else glCullFace((CULL_DRAW_CCW == cm) ? GL_FRONT : GL_BACK);

   // Depth test for 3D projection
   if (NULL != camera)glEnable(GL_DEPTH_TEST);

   // Drawing color.
   glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}


// End drawing. Set "was3D" to true if you specified a camera at leglBegin (= used 3D projection).
void leglEnd(bool was3D)
{
   // Undo changes only made in 3D mode (camera != NULL)
   if (was3D) 
   {
       glMatrixMode(GL_PROJECTION); glPopMatrix();
       glDisable(GL_DEPTH_TEST);
   }
   else
       glPopMatrix();

   // Reset transformation.
   glMatrixMode(GL_MODELVIEW); glPopMatrix();

   // Undo changed settings.
   glDisable(GL_BLEND);
   glCullFace(GL_BACK); glDisable(GL_CULL_FACE);
   glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
   //leglBindTexture(NULL);
}


void leglBindTexture(TTexture texture)
{
    if(NULL != texture)
   {
       glEnable(GL_TEXTURE_2D);
       BindTexture(texture, 0); // LE command.
   }
   else
   {
       glBindTexture(GL_TEXTURE_2D, NULL);
       glDisable(GL_TEXTURE_2D);
   }
}

void leglDrawImageRect(int x, int y, int w, int h, TTexture image, TVec3 rotation, TVec3 scale)
{
leglBegin();
glTranslatef(w/2,h/2,0.0);
// rotate it by angle required..
// rotate X
if(rotation.X != 0.0)
	glRotatef(rotation.X,1.0,0.0,0.0);
if(rotation.Y != 0.0)
	glRotatef(rotation.Y,0.0,1.0,0.0);
if(rotation.Z != 0.0)
	glRotatef(rotation.Z,0.0,0.0,1.0);
// reset the rotation origin..
//glTranslatef(size.X/2,size.Y/2,0.0);
glTranslatef(0-w/2,0-h/2,0.0);
// build the plane at 0,0... by size x and y 
glScalef(scale.X, scale.Y, scale.Z);

if(image != NULL)
	leglBindTexture(image); // LE command.
glBegin(GL_QUADS);
	glVertex2i(x,y);
	glVertex2i(x+w,y);
	glVertex2i(x+w,y+h);
	glVertex2i(x,y+h);
glEnd();
leglEnd();

}

 

Like I said this works in a different project, so I don't know what I am doing wrong and see no difference in code....

If it's not Tactical realism then you are just playing..

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...