Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I have a program in visual Studio C++ but somthing is wrong and it doesn't work.
C++
#include <windows.h>
#include <gl/glut.h>
#include <stdlib.h>
#include <math.h>
#include <ctime>
#include <cstdlib>

#include <gl/gl.h>
#define randomize() (srand(time(0)))
#define random(x) (rand() % x)

#include "opengl.h"
#include "Complex_Number.cpp"

// Prototype for calculation of the pixel
Complex_Number getest(Complex_Number pt, Complex_Number c_temp);
// Define global functions/variables used in creating the fractal
void drawfractal(MSG msg, HDC hDC);
bool bQuit = false;  // termination condition
int color=0;
int GLOB;
LRESULT CALLBACK
WndProc( HWND hWnd, UINT message,
         WPARAM wParam, LPARAM lParam );
// WinMain
int WINAPI
void Main( HINSTANCE hInstance,
         HINSTANCE hPrevInstance,
         LPSTR lpCmdLine,
         int iCmdShow )
{
  WNDCLASS wc;
  HWND hWnd;
  HDC hDC;
  HGLRC hRC;
  MSG msg;
  int cx=GetSystemMetrics(SM_CXSCREEN);
  int cy=GetSystemMetrics(SM_CYSCREEN);
  // register window class
  wc.style = CS_OWNDC;
  wc.lpfnWndProc = WndProc;
  wc.cbClsExtra = 0;
  wc.cbWndExtra = 0;
  wc.hInstance = hInstance;
  wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
  wc.hCursor = LoadCursor( NULL, IDC_CROSS );
  wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
  wc.lpszMenuName = NULL;
  wc.lpszClassName = "Fractal";
  RegisterClass( &wc );
  // create main window
  hWnd = CreateWindow(
    "Fractal", "Fractal",
    WS_POPUPWINDOW | WS_VISIBLE,
    0, 0, cx, cy,        //cx, cy
    NULL, NULL, hInstance, NULL );

  // enable OpenGL for the window
   EnableOpenGL( hWnd, &hDC, &hRC );
	randomize();
  // program main loop
  while ( !bQuit ) {
    // check for messages
    if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) {
      // handle or dispatch messages
      if ( msg.message == WM_QUIT ) {
        bQuit = TRUE;
      } else {
        TranslateMessage( &msg );
        DispatchMessage( &msg );
      }
    }
	 /* Create Fractal and display on screen */
    else
    {
      GLOB=rand()%10+1;
	   drawfractal(msg, hDC);
		color++;
   }
  }

  // shutdown OpenGL
  DisableOpenGL( hWnd, hDC, hRC );
  // destroy the window explicitly
  DestroyWindow( hWnd );
  return msg.wParam;
}
// Window Procedure
LRESULT CALLBACK
WndProc( HWND hWnd, UINT message,
         WPARAM wParam, LPARAM lParam )
{
  switch ( message ) {
  case WM_CREATE:
    return 0;
  case WM_LBUTTONDOWN:
  	bQuit = TRUE;
   return 0;
  case WM_RBUTTONDOWN:
  	bQuit = TRUE;
   return 0;
  case WM_SETCURSOR:
    SetCursor(NULL);
    break;

  case WM_MOUSEMOVE:
// uncomment for screen saver version
/*      POINT pt;
    GetCursorPos(&pt);
    if ((m_ypos == -1) && (m_xpos == -1)) // have not captured mouse yet...
    	{
	    m_xpos = pt.x;
	    m_ypos = pt.y;
      }
    else {
    	if ((pt.x != m_xpos) || (pt.y != m_ypos)) bQuit=TRUE;
      }
*/
    return 0;
  case WM_KEYDOWN:
  bQuit = TRUE;
  return 0;
  case WM_CLOSE:
    PostQuitMessage( 0 );
    return 0;
  case WM_DESTROY:
    return 0;
  default:
    return DefWindowProc( hWnd,
      message, wParam, lParam );
  }
  return 0;
}
void drawfractal(MSG msg, HDC hDC)
{
double a, b;
Complex_Number c(0,-1);
Complex_Number point(1,1);
Complex_Number temp(0,0);
const double STEP = .0017; // Pixel Separation
const double bound = 1;  // Screen bounds
for (double y = -bound; y<bound; y+=STEP) {
for (double x = -bound; x<bound; x+=STEP) {
	if (bQuit == TRUE) break;  // must still yield control
   // This yields control to windows
   // while still executing a CPU intensive loop
    if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) {
      if ( msg.message == WM_QUIT ){ 	bQuit = TRUE;}
      else {
        TranslateMessage( &msg );
        DispatchMessage( &msg );
      }
    }
   // Now for the CPU intensive part
   else
   {
	   glBegin(GL_POINTS);
	   point = getest(point, c);
      point.Get_ab(a, b);
      glVertex2d(a,b);
   	glEnd();
      point.Set_ab(x, y);
   }
 }
      SwapBuffers( hDC );
      glFlush();
 }  //End of for loop
}
Complex_Number getest(Complex_Number pt, Complex_Number c_temp)
{
double red=0;
double green=0;
double blue=0;
   double a, b;
   pt.Get_ab(a, b);
	Complex_Number temp(a,b);
   for (int i=0; i<15; i++) {
	   double j, k;
   // get good estimate for point
   // need to test if going infinity or not.
	   for (int dum=0; dum < GLOB; dum ++)
	   {
	  		temp.Multiply(pt);
	   }
	      temp.Add(c_temp);
	      temp.Get_ab(j, k);
	      pt.Set_ab(j,k);
	      	if ((fabs(j) > 10) || (fabs(k) > 10))
		      {
					red =log(fabs(k)+1)*.25;
	            green=sin(.005*j);
	            blue=(1/log(i+2))*.25;
			      break;
	         }
   	}
	// set color based on observations....
	if (color%5==0)
		glColor3f (blue,green,red);// blue
	else if (color%2==0)
		glColor3f (green,red,blue);// green
	else
		glColor3f (red,blue,green); //red
	pt.Set_ab(a,b);
	return pt;
}


this program has run time error and i cant run the program. - [email address removed]
Posted
Updated 11-Jan-11 0:59am
v3
Comments
Sergey Alexandrovich Kryukov 11-Jan-11 0:09am    
There are infinite number of fractals. What's the definition of the one you want to show? Just curious. I don't event want to decode your code to figure out. What does it mean: "doesn't work"?
Richard MacCutchan 11-Jan-11 6:33am    
Edited for code formatting.
What run time error? Where does it occur? We cannot guess what your problem is just by looking at the code.
CPallini 11-Jan-11 7:01am    
Exposing your email address this way is just silly.

BTW: You should post a meaningful request here, not tons of code with the vague indication that "it doesn't work".
Sandeep Mewara 11-Jan-11 7:07am    
What error?

1 solution

Thanks for posting the code here.
Now what is your question?
 
Share this answer
 
Comments
nima6868@yahoo.com 11-Jan-11 0:07am    
this program has run time error and i cant run the program.
Sergey Alexandrovich Kryukov 11-Jan-11 0:10am    
@Abhinav: Frankly, this post is not and answer. How about a comment?
Sergey Alexandrovich Kryukov 11-Jan-11 0:13am    
@nima6868@yahoo.com: this is not an adequate way of response, sorry.
Shall we pull answers from you? Who is interested?

Ok, adequate level of detail please. Exact error message, in what line of code (under debugger)?
Be prepare to catch an exception and post a complete exception dump.
Ankur\m/ 11-Jan-11 6:38am    
@nima6868@yahoo.com: Then debug it and find WHAT and WHERE the problem is.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900