• Advertisement
Sign in to follow this  

Runs but...

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

The catch is, it will only run under vc++ when you execute it under the debug (Ctrl+F5). It runs the program just fine but when I try to see if it would run by going into the folder(outside of vc++) where it's located at and just double clicking the executable it can't. I then tried to narrow it down and found that it gives me an error about glRasterPos or the Targa Image. I'm not sure if there is something wierd with the code but if anyone can think of anything it sure would help. The Two functions to look at would be init or render. I also did a lot of searching (a day or two) before posting this to not try and waste. anyone's time
//////////////////
//CGfxOpenGL CPP//
//////////////////
#ifndef _WINDOWS
#include <windows.h>
#endif

#include <glee.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <math.h>
#include "CGfxOpenGL.h"
#include "mTargaImage.h"


class GLUquadric{};	//Fixes Linking Problem
//#pragma unmanaged

//My Set Colors
GLfloat Green[] = {0.0f, 1.0f, 0.0f, 1.0f};
GLfloat Blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
GLfloat White[] = {1.0f, 1.0f, 1.0f, 1.0f};
GLfloat Black[] = {0.0f, 0.0f, 0.0f, 1.0f};

//BitMap
unsigned char LetterX [] = {
					0x80, 0x01,
					0x40, 0x02,
					0x20, 0x04,
					0x10, 0x08,
					0x08, 0x10,
					0x04, 0x20,
					0x02, 0x40,
					0x01, 0x80,
					0x01, 0x80,
					0x02, 0x40,
					0x04, 0x20,
					0x08, 0x10,
					0x10, 0x08,
					0x20, 0x04,
					0x40, 0x02,
					0x80, 0x01};

CGfxOpenGL::CGfxOpenGL()
{
}



CGfxOpenGL::~CGfxOpenGL()
{
}



bool CGfxOpenGL::Init()
{
	////////
	//Init//
	////////

	m_angle = 0.0f;

	//Animate Objects to Intersect Each Other
	xpos = 0.0f;
	dir = true;

	m_pSphere = gluNewQuadric();


	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	::glEnable(GL_DEPTH_TEST);


	////////////////////
	//Targa Image Init//
	////////////////////

	Image = new mTargaImage;
	Image2 = new mTargaImage;

	if(!Image->Load("opengl_logo.tga"))
		return false;

	if(!Image2->Load("opengl_logo_un.tga"))
		return false;

	////////////////////////////////
	//Texture Object/Generation #1//
	////////////////////////////////

	::glEnable(GL_TEXTURE_2D);

	Image3 = new mTargaImage;

	if(!Image3->Load("checkerboard.tga"))
		return false;

	::glGenTextures(1, &m_tObj);
	::glBindTexture(GL_TEXTURE_2D, m_tObj);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

	::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, Image3->GetWidth(), Image3->GetHeight(), 0, 
		GL_RGB, GL_UNSIGNED_BYTE, Image3->GetImage());


	////////////////////////////////
	//Texture Object/Generation #2//
	////////////////////////////////

	Image4 = new mTargaImage;

	if(!Image4->Load("rock.tga"))
		return false;

	::glGenTextures(1, &m_tObj2);
	::glBindTexture(GL_TEXTURE_2D, m_tObj2);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

	::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, Image3->GetWidth(), Image4->GetHeight(), 0, 
		GL_RGB, GL_UNSIGNED_BYTE, Image4->GetImage());


	///////
	//Fog//
	///////

	::glEnable(GL_FOG);
	::glFogi(GL_FOG_COORD_SRC, GL_FRAGMENT_DEPTH);
	::glFogfv(GL_FOG_COLOR, Black); 
	::glFogf(GL_FOG_DENSITY, 0.1f);
	::glFogf(GL_FOG_MODE, GL_EXP2); 
	

	//////////
	//Lights//
	//////////
	
	glEnable(GL_LIGHTING);
	

	//glEnable(GL_COLOR_MATERIAL);	//makes it easier to color materials
	::glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
	::glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
	::glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);	//Deals with texture mapping -> to show specular better

	

	glEnable(GL_LIGHT0);

	glLightfv(GL_LIGHT0, GL_DIFFUSE, White);
	glLightfv(GL_LIGHT0, GL_AMBIENT, White);
	glLightfv(GL_LIGHT0, GL_SPECULAR, White);
	glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.1f);

	glTranslatef(0.0f, 10.0f, 0.0f);
	GLfloat lightPos[] = {0.0f, 0.0f, 0.0f, 1.0f};
	glLightfv(GL_LIGHT0, GL_POSITION, lightPos);


	return true;
}



bool CGfxOpenGL::ShutDown()
{
  if (m_pSphere)
    gluDeleteQuadric(m_pSphere);
  m_pSphere = NULL;

  glDeleteTextures(1, &m_tObj);
  glDeleteTextures(1, &m_tObj2);

  Image->Release();
  delete Image;

  Image2->Release();
  delete Image2;

  Image3->Release();
  delete Image3;

  Image4->Release();
  delete Image4;

	return true;
}


void CGfxOpenGL::SetupProjection(unsigned int width, unsigned int height)
{
	if(height <= 0)
	{
		height = 1;
	}

	//3D ViewPort -> Same Size as Window
	glViewport(0, 0, width, height);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	// Calculate aspect ratio of window
	gluPerspective(52.0f, (GLfloat)width/(GLfloat)height, 0.01f, 1000.0f);
	//gluOrtho2D(100, 100, 100, 100);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	m_windowWidth = width;
	m_windowHeight = height;

}



void CGfxOpenGL::Prepare(float dt)
{
	m_angle += 0.1f;


	//Used to Intersect the Sphere and Cube
	if(dir)
		xpos -= 0.001f;
	else
		xpos += 0.001f;

	if(xpos >= 2.0f)
		dir = true;
	else if (xpos <= -2.0f)
		dir = false;


}



void CGfxOpenGL::Render()
{
	//Clear Screen and Bit Buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
	glLoadIdentity();


	gluLookAt(0.0f, -0.2f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);


	//Enabling Blend
	::glEnable(GL_BLEND);
	::glBlendFunc(GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA);
	//::glBlendEquation(GL_FUNC_SUBTRACT);
	//::glDepthMask(GL_FALSE);


	//////////////////////////////////
	// Draw Plane -> Color : White////
	//////////////////////////////////

	//GLfloat cubeColor3[] = { 0.6f, 0.7f, 0.1f, 1.0f };
	GLfloat cubeColor3[] = { 1.0f, 1.0f, 1.0f, 1.0f };
	GLfloat cubeSpecular3[] = { 1.0f, 1.0f, 1.0f, 1.0f };
	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, cubeColor3);
	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, cubeSpecular3);
	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 10.0f);

	::glPushMatrix();
		::glTranslatef(0.0f, -2.5f, -5.0f);
		::glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
		::glScalef(20.0f, 0.0f, 20.0f);
		::glBindTexture(GL_TEXTURE_2D, m_tObj);
		mPlane();
	::glPopMatrix();


	///////////////////////////////
	// Draw Sphere -> Color : Red//
	///////////////////////////////

	GLfloat cubeColor[] = { 0.6f, 0.0f, 0.0f, 1.0f };
	GLfloat cubeSpecular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, cubeColor);
	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, cubeSpecular);
	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 10.0f);
		
	glPushMatrix();
		glTranslatef(-xpos, 0.0f, -5.0f);
		::glRotatef(m_angle, 1.0f, 0.0f, 0.0f);
		::glRotatef(m_angle, 0.0f, 1.0f, 0.0f);
		::glRotatef(m_angle, 0.0f, 0.0f, 1.0f);
		::gluQuadricTexture(m_pSphere, GLU_TRUE);
		::glBindTexture(GL_TEXTURE_2D, m_tObj);
		gluSphere(m_pSphere, 1.0f, 32, 32);
	glPopMatrix();


	/////////////////////////////////
	// Draw Cube -> Color : Blueish//
	/////////////////////////////////

	GLfloat cubeColor2[] = { 0.6f, 0.7f, 1.0f, 0.5f };
	GLfloat cubeSpecular2[] = { 1.0f, 1.0f, 1.0f, 1.0f };
	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, cubeColor2);
	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, cubeSpecular2);
	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 10.0f);

	::glPushMatrix();
		::glTranslatef(xpos, 0.0f, -5.0f);
		::glRotatef(m_angle, 1.0f, 0.0f, 0.0f);
		::glRotatef(m_angle, 0.0f, 1.0f, 0.0f);
		::glRotatef(m_angle, 0.0f, 0.0f, 1.0f);
		::glBindTexture(GL_TEXTURE_2D, m_tObj2);
		mCube2(GL_FRONT_AND_BACK, GL_FILL);
	::glPopMatrix();


	::glDisable(GL_BLEND);


	::glDisable(GL_LIGHTING);

	/////////////
	//GL BITMAP//
	/////////////

	::glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	::glRasterPos2i(0, 0);
	::glColor3f(1.0f, 1.0f, 1.0f);
	::glBitmap(16, 16, 0, 0, 0, 0, LetterX);
	

	///////////////
	//TARGA IMAGE//
	///////////////

	::glRasterPos2f(-3.18f, -2.395f);
	::glPixelZoom(0.3f, 0.3f);
	::glDrawPixels(Image->GetWidth(), Image->GetHeight(), GL_RGB, GL_UNSIGNED_BYTE, Image->GetImage());

	::glRasterPos2f(2.05f, 1.85f);
	::glPixelZoom(0.3f, 0.3f);
	::glDrawPixels(Image2->GetWidth(), Image2->GetHeight(), GL_RGB, GL_UNSIGNED_BYTE, Image2->GetImage());

	::glEnable(GL_LIGHTING);
}



Share this post


Link to post
Share on other sites
Advertisement
Where are opengl_logo.tga and opengl_logo_un.tga in relation to the .EXE file?

Share this post


Link to post
Share on other sites
Thanks, that's what it was!! I didn't put the image files where the .exe file was.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement